home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Sources-CPlus / cp-decl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  358.4 KB  |  11,578 lines  |  [TEXT/MPS ]

  1. /* Process declarations and variables for C compiler.
  2.    Copyright (C) 1988, 1992 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@cygnus.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* Process declarations and symbol lookup for C front end.
  23.    Also constructs types; the standard scalar types at initialization,
  24.    and structure, union, array and enum types when they are declared.  */
  25.  
  26. /* ??? not all decl nodes are given the most useful possible
  27.    line numbers.  For example, the CONST_DECLs for enum values.  */
  28.  
  29. #include <stdio.h>
  30. #include "config.h"
  31. #include "tree.h"
  32. #include "rtl.h"
  33. #include "flags.h"
  34. #include "cp-tree.h"
  35. #include "cp-lex.h"
  36. #ifndef MPW
  37. #include <sys/types.h>
  38. #endif
  39. #include <signal.h>
  40. #include "obstack.h"
  41.  
  42. #define obstack_chunk_alloc xmalloc
  43. #define obstack_chunk_free free
  44.  
  45. extern struct obstack permanent_obstack;
  46.  
  47. /* Stack of places to restore the search obstack back to.  */
  48.    
  49. /* Obstack used for remembering local class declarations (like
  50.    enums and static (const) members.  */
  51. #include "stack.h"
  52. static struct obstack decl_obstack;
  53. static struct stack_level *decl_stack;
  54.  
  55. #include "cp-decl.h"
  56.  
  57. #undef NULL
  58. #define NULL 0
  59.  
  60. #ifndef CHAR_TYPE_SIZE
  61. #define CHAR_TYPE_SIZE BITS_PER_UNIT
  62. #endif
  63.  
  64. #ifndef SHORT_TYPE_SIZE
  65. #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
  66. #endif
  67.  
  68. #ifndef INT_TYPE_SIZE
  69. #define INT_TYPE_SIZE BITS_PER_WORD
  70. #endif
  71.  
  72. #ifndef LONG_TYPE_SIZE
  73. #define LONG_TYPE_SIZE BITS_PER_WORD
  74. #endif
  75.  
  76. #ifndef LONG_LONG_TYPE_SIZE
  77. #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
  78. #endif
  79.  
  80. #ifndef WCHAR_UNSIGNED
  81. #define WCHAR_UNSIGNED 0
  82. #endif
  83.  
  84. #ifndef FLOAT_TYPE_SIZE
  85. #define FLOAT_TYPE_SIZE BITS_PER_WORD
  86. #endif
  87.  
  88. #ifndef DOUBLE_TYPE_SIZE
  89. #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  90. #endif
  91.  
  92. #ifndef LONG_DOUBLE_TYPE_SIZE
  93. #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  94. #endif
  95.  
  96. /* We let tm.h override the types used here, to handle trivial differences
  97.    such as the choice of unsigned int or long unsigned int for size_t.
  98.    When machines start needing nontrivial differences in the size type,
  99.    it would be best to do something here to figure out automatically
  100.    from other information what type to use.  */
  101.  
  102. #ifndef SIZE_TYPE
  103. #define SIZE_TYPE "long unsigned int"
  104. #endif
  105.  
  106. #ifndef PTRDIFF_TYPE
  107. #define PTRDIFF_TYPE "long int"
  108. #endif
  109.  
  110. #ifndef WCHAR_TYPE
  111. #define WCHAR_TYPE "int"
  112. #endif
  113.  
  114. static tree grokparms ();
  115. tree grokdeclarator ();
  116. tree pushdecl (), pushdecl_class_level ();
  117. void pop_implicit_try_blocks ();
  118.  
  119. #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
  120.   define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
  121. #define auto_function(NAME, TYPE, CODE) \
  122.   do {                    \
  123.     tree __name = NAME;        \
  124.     tree __type = TYPE;            \
  125.     define_function (IDENTIFIER_POINTER (__name), __type, CODE,    \
  126.              (void (*)())push_overloaded_decl_1,    \
  127.              IDENTIFIER_POINTER (build_decl_overload (__name, TYPE_ARG_TYPES (__type), 0)));\
  128.   } while (0)
  129.  
  130. /* These are defined in their respective cp-* files.  */
  131. extern void init_search_processing ();
  132. extern void init_class_processing (); 
  133. extern void init_init_processing ();
  134. extern void init_exception_processing ();
  135. extern void init_gc_processing ();
  136. extern void init_cadillac ();
  137.  
  138.  
  139. /* static */ void grokclassfn ();
  140. /* static */ tree grokoptypename ();
  141.  
  142. static tree lookup_tag ();
  143. static tree lookup_tag_reverse ();
  144. static tree lookup_name_current_level ();
  145. static void maybe_globalize_type (), globalize_nested_type ();
  146. static tree lookup_nested_type ();
  147. static char *redeclaration_error_message ();
  148. int parmlist_is_exprlist ();
  149. static int parmlist_is_random ();
  150. void grok_ctor_properties ();
  151. static void grok_op_properties ();
  152. static void expand_static_init ();
  153. static void deactivate_exception_cleanups ();
  154. static void revert_static_member_fn ();
  155. void adjust_type_value ();
  156.  
  157. tree finish_table ();
  158.  
  159. /* a node which has tree code ERROR_MARK, and whose type is itself.
  160.    All erroneous expressions are replaced with this node.  All functions
  161.    that accept nodes as arguments should avoid generating error messages
  162.    if this node is one of the arguments, since it is undesirable to get
  163.    multiple error messages from one error in the input.  */
  164.  
  165. tree error_mark_node;
  166.  
  167. /* Erroneous argument lists can use this *IFF* they do not modify it.  */
  168. tree error_mark_list;
  169.  
  170. /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
  171.  
  172. tree short_integer_type_node;
  173. tree integer_type_node;
  174. tree long_integer_type_node;
  175. tree long_long_integer_type_node;
  176.  
  177. tree short_unsigned_type_node;
  178. tree unsigned_type_node;
  179. tree long_unsigned_type_node;
  180. tree long_long_unsigned_type_node;
  181.  
  182. tree ptrdiff_type_node;
  183.  
  184. tree unsigned_char_type_node;
  185. tree signed_char_type_node;
  186. tree char_type_node;
  187. tree wchar_type_node;
  188. tree signed_wchar_type_node;
  189. tree unsigned_wchar_type_node;
  190.  
  191. tree float_type_node;
  192. tree double_type_node;
  193. tree long_double_type_node;
  194.  
  195. tree intQI_type_node;
  196. tree intHI_type_node;
  197. tree intSI_type_node;
  198. tree intDI_type_node;
  199.  
  200. tree unsigned_intQI_type_node;
  201. tree unsigned_intHI_type_node;
  202. tree unsigned_intSI_type_node;
  203. tree unsigned_intDI_type_node;
  204.  
  205. /* a VOID_TYPE node, and the same, packaged in a TREE_LIST.  */
  206.  
  207. tree void_type_node, void_list_node;
  208. tree void_zero_node;
  209.  
  210. /* Nodes for types `void *' and `const void *'.  */
  211.  
  212. tree ptr_type_node, const_ptr_type_node;
  213.  
  214. /* Nodes for types `char *' and `const char *'.  */
  215.  
  216. tree string_type_node, const_string_type_node;
  217.  
  218. /* Type `char[256]' or something like it.
  219.    Used when an array of char is needed and the size is irrelevant.  */
  220.  
  221. tree char_array_type_node;
  222.  
  223. /* Type `int[256]' or something like it.
  224.    Used when an array of int needed and the size is irrelevant.  */
  225.  
  226. tree int_array_type_node;
  227.  
  228. /* Type `wchar_t[256]' or something like it.
  229.    Used when a wide string literal is created.  */
  230.  
  231. tree wchar_array_type_node;
  232.  
  233. /* type `int ()' -- used for implicit declaration of functions.  */
  234.  
  235. tree default_function_type;
  236.  
  237. /* function types `double (double)' and `double (double, double)', etc.  */
  238.  
  239. tree double_ftype_double, double_ftype_double_double;
  240. tree int_ftype_int, long_ftype_long;
  241. #ifdef APPLE_HAX
  242. /* Function type `extended (extended)', used with -elems881. */
  243. tree extended_ftype_extended;
  244. #endif /* APPLE_HAX */
  245.  
  246. /* Function type `void (void *, void *, int)' and similar ones.  */
  247.  
  248. tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
  249.  
  250. /* Function type `char *(char *, char *)' and similar ones */
  251. tree string_ftype_ptr_ptr, int_ftype_string_string;
  252.  
  253. /* Function type `size_t (const char *)' */
  254. tree sizet_ftype_string;
  255.  
  256. /* Function type `int (const void *, const void *, size_t)' */
  257. tree int_ftype_cptr_cptr_sizet;
  258.  
  259. /* C++ extensions */
  260. tree vtable_entry_type;
  261. tree __t_desc_type_node, __i_desc_type_node, __m_desc_type_node;
  262. tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
  263. tree class_star_type_node;
  264. tree class_type_node, record_type_node, union_type_node, enum_type_node;
  265. tree exception_type_node, unknown_type_node;
  266. tree maybe_gc_cleanup;
  267.  
  268. /* Used for virtual function tables.  */
  269. tree vtbl_mask;
  270.  
  271. /* Array type `(void *)[]' */
  272. tree vtbl_type_node;
  273.  
  274. #ifdef SOS
  275. /* SOS extensions.  */
  276. tree zlink_type, zret_type;
  277. tree zlink, zret;
  278. #endif
  279.  
  280. /* Static decls which do not have static initializers have no
  281.    initializers as far as GNU C is concerned.  EMPTY_INIT_NODE
  282.    is a static initializer which makes varasm code place the decl
  283.    in data rather than in bss space.  Such gymnastics are necessary
  284.    to avoid the problem that the linker will not include a library
  285.    file if all the library appears to contribute are bss variables.  */
  286.  
  287. tree empty_init_node;
  288.  
  289. /* In a destructor, the point at which all derived class destroying
  290.    has been done, just before any base class destroying will be done.  */
  291.  
  292. tree dtor_label;
  293.  
  294. /* In a constructor, the point at which we are ready to return
  295.    the pointer to the initialized object.  */
  296.  
  297. tree ctor_label;
  298.  
  299. /* A FUNCTION_DECL which can call `unhandled_exception'.
  300.    Not necessarily the one that the user will declare,
  301.    but sufficient to be called by routines that want to abort the program.  */
  302.  
  303. tree unhandled_exception_fndecl;
  304.  
  305. /* A FUNCTION_DECL which can call `abort'.  Not necessarily the
  306.    one that the user will declare, but sufficient to be called
  307.    by routines that want to abort the program.  */
  308.  
  309. tree abort_fndecl;
  310.  
  311. extern rtx cleanup_label, return_label;
  312.  
  313. /* If original DECL_RESULT of current function was a register,
  314.    but due to being an addressable named return value, would up
  315.    on the stack, this variable holds the named return value's
  316.    original location.  */
  317. rtx original_result_rtx;
  318.  
  319. /* Sequence of insns which represents base initialization.  */
  320. rtx base_init_insns;
  321.  
  322. /* C++: Keep these around to reduce calls to `get_identifier'.
  323.    Identifiers for `this' in member functions and the auto-delete
  324.    parameter for destructors.  */
  325. tree this_identifier, in_charge_identifier;
  326.  
  327. /* A list (chain of TREE_LIST nodes) of named label uses.
  328.    The TREE_PURPOSE field is the list of variables defined
  329.    the the label's scope defined at the point of use.
  330.    The TREE_VALUE field is the LABEL_DECL used.
  331.    The TREE_TYPE field holds `current_binding_level' at the
  332.    point of the label's use.
  333.  
  334.    Used only for jumps to as-yet undefined labels, since
  335.    jumps to defined labels can have their validity checked
  336.    by stmt.c.  */
  337.  
  338. static tree named_label_uses;
  339.  
  340. /* A list of objects which have constructors or destructors
  341.    which reside in the global scope.  The decl is stored in
  342.    the TREE_VALUE slot and the initializer is stored
  343.    in the TREE_PURPOSE slot.  */
  344. tree static_aggregates;
  345.  
  346. /* A list of functions which were declared inline, but later had their
  347.    address taken.  Used only for non-virtual member functions, since we can
  348.    find other functions easily enough.  */
  349. tree pending_addressable_inlines;
  350.  
  351. /* A list of overloaded functions which we should forget ever
  352.    existed, such as functions declared in a function's scope,
  353.    once we leave that function's scope.  */
  354. static tree overloads_to_forget;
  355.  
  356. /* -- end of C++ */
  357.  
  358. /* Two expressions that are constants with value zero.
  359.    The first is of type `int', the second of type `void *'.  */
  360.  
  361. tree integer_zero_node;
  362. #if defined(APPLE_HAX) && defined(PTR_HACK)
  363. tree null_DPpointer_node;
  364. tree null_TPpointer_node;
  365. #else
  366. tree null_pointer_node;
  367. #endif
  368.  
  369. /* A node for the integer constants 1, 2, and 3.  */
  370.  
  371. tree integer_one_node, integer_two_node, integer_three_node;
  372.  
  373. /* Nonzero if we have seen an invalid cross reference
  374.    to a struct, union, or enum, but not yet printed the message.  */
  375.  
  376. tree pending_invalid_xref;
  377. /* File and line to appear in the eventual error message.  */
  378. char *pending_invalid_xref_file;
  379. int pending_invalid_xref_line;
  380.  
  381. /* While defining an enum type, this is 1 plus the last enumerator
  382.    constant value.  */
  383.  
  384. static tree enum_next_value;
  385.  
  386. /* Parsing a function declarator leaves a list of parameter names
  387.    or a chain or parameter decls here.  */
  388.  
  389. tree last_function_parms;
  390.  
  391. /* Parsing a function declarator leaves here a chain of structure
  392.    and enum types declared in the parmlist.  */
  393.  
  394. static tree last_function_parm_tags;
  395.  
  396. /* After parsing the declarator that starts a function definition,
  397.    `start_function' puts here the list of parameter names or chain of decls.
  398.    `store_parm_decls' finds it here.  */
  399.  
  400. static tree current_function_parms;
  401.  
  402. /* Similar, for last_function_parm_tags.  */
  403. static tree current_function_parm_tags;
  404.  
  405. /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
  406.    that have names.  Here so we can clear out their names' definitions
  407.    at the end of the function.  */
  408.  
  409. static tree named_labels;
  410.  
  411. /* A list of LABEL_DECLs from outer contexts that are currently shadowed.  */
  412.  
  413. static tree shadowed_labels;
  414.  
  415. #if 0 /* Not needed by C++ */
  416. /* Nonzero when store_parm_decls is called indicates a varargs function.
  417.    Value not meaningful after store_parm_decls.  */
  418.  
  419. static int c_function_varargs;
  420. #endif
  421.  
  422. /* The FUNCTION_DECL for the function currently being compiled,
  423.    or 0 if between functions.  */
  424. tree current_function_decl;
  425.  
  426. /* Set to 0 at beginning of a function definition, set to 1 if
  427.    a return statement that specifies a return value is seen.  */
  428.  
  429. int current_function_returns_value;
  430.  
  431. /* Set to 0 at beginning of a function definition, set to 1 if
  432.    a return statement with no argument is seen.  */
  433.  
  434. int current_function_returns_null;
  435.  
  436. /* Set to 0 at beginning of a function definition, and whenever
  437.    a label (case or named) is defined.  Set to value of expression
  438.    returned from function when that value can be transformed into
  439.    a named return value.  */
  440.  
  441. tree current_function_return_value;
  442.  
  443. /* Nonzero means warn about multiple (redundant) decls for the same single
  444.    variable or function.  */
  445.  
  446. extern int warn_redundant_decls;
  447.  
  448. /* Set to nonzero by `grokdeclarator' for a function
  449.    whose return type is defaulted, if warnings for this are desired.  */
  450.  
  451. static int warn_about_return_type;
  452.  
  453. /* Nonzero when starting a function declared `extern inline'.  */
  454.  
  455. static int current_extern_inline;
  456.  
  457. /* Nonzero means give `double' the same size as `float'.  */
  458.  
  459. extern int flag_short_double;
  460.  
  461. /* Nonzero means handle things in ANSI, instead of GNU fashion.  This
  462.    flag should be tested for language behavior that's different between
  463.    ANSI and GNU, but not so horrible as to merit a PEDANTIC label.  */
  464.  
  465. extern int flag_ansi;
  466.  
  467. /* Pointers to the base and current top of the language name stack.  */
  468.  
  469. extern tree *current_lang_base, *current_lang_stack;
  470.  
  471. /* C and C++ flags are in cp-decl2.c.  */
  472. char *language_string = "GNU C++";
  473.  
  474. /* Set to 0 at beginning of a constructor, set to 1
  475.    if that function does an allocation before referencing its
  476.    instance variable.  */
  477. int current_function_assigns_this;
  478. int current_function_just_assigned_this;
  479.  
  480. /* Set to 0 at beginning of a function.  Set non-zero when
  481.    store_parm_decls is called.  Don't call store_parm_decls
  482.    if this flag is non-zero!  */
  483. int current_function_parms_stored;
  484.  
  485. /* Current end of entries in the gc obstack for stack pointer variables.  */
  486.  
  487. int current_function_obstack_index;
  488.  
  489. /* Flag saying whether we have used the obstack in this function or not.  */
  490.  
  491. int current_function_obstack_usage;
  492.  
  493. /* Flag used when debugging cp-spew.c */
  494.  
  495. extern int spew_debug;
  496.  
  497. /* Allocate a level of searching.  */
  498. struct stack_level *
  499. push_decl_level (stack, obstack)
  500.      struct stack_level *stack;
  501.      struct obstack *obstack;
  502. {
  503.   struct stack_level tem;
  504.   tem.prev = stack;
  505.  
  506.   return push_stack_level (obstack, &tem, sizeof (tem));
  507. }
  508.  
  509. /* Discard a level of decl allocation.  */
  510.  
  511. static struct stack_level *
  512. pop_decl_level (stack)
  513.      struct stack_level *stack;
  514. {
  515.   tree *bp, *tp;
  516.   struct obstack *obstack = stack->obstack;
  517.   bp = stack->first;
  518.   tp = (tree *)obstack_next_free (obstack);
  519.   while (tp != bp)
  520.     {
  521.       --tp;
  522.       if (*tp != NULL_TREE)
  523.     IDENTIFIER_CLASS_VALUE (DECL_NAME (*tp)) = NULL_TREE;
  524.     }
  525.   return pop_stack_level (stack);
  526. }
  527.  
  528. /* For each binding contour we allocate a binding_level structure
  529.  * which records the names defined in that contour.
  530.  * Contours include:
  531.  *  0) the global one
  532.  *  1) one for each function definition,
  533.  *     where internal declarations of the parameters appear.
  534.  *  2) one for each compound statement,
  535.  *     to record its declarations.
  536.  *
  537.  * The current meaning of a name can be found by searching the levels from
  538.  * the current one out to the global one.
  539.  *
  540.  * Off to the side, may be the class_binding_level.  This exists
  541.  * only to catch class-local declarations.  It is otherwise
  542.  * nonexistent.
  543.  * 
  544.  * Also there may be binding levels that catch cleanups that
  545.  * must be run when exceptions occur.
  546.  */
  547.  
  548. /* Note that the information in the `names' component of the global contour
  549.    is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
  550.  
  551. struct binding_level
  552.   {
  553.     /* A chain of _DECL nodes for all variables, constants, functions,
  554.      * and typedef types.  These are in the reverse of the order supplied.
  555.      */
  556.     tree names;
  557.  
  558.     /* A list of structure, union and enum definitions,
  559.      * for looking up tag names.
  560.      * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
  561.      * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
  562.      * or ENUMERAL_TYPE node.
  563.      *
  564.      * C++: the TREE_VALUE nodes can be simple types for component_bindings.
  565.      *
  566.      */
  567.     tree tags;
  568.  
  569.     /* For each level, a list of shadowed outer-level local definitions
  570.        to be restored when this level is popped.
  571.        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
  572.        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
  573.     tree shadowed;
  574.  
  575.     /* Same, for IDENTIFIER_CLASS_VALUE.  */
  576.     tree class_shadowed;
  577.  
  578.     /* Same, for IDENTIFIER_TYPE_VALUE.  */
  579.     tree type_shadowed;
  580.  
  581.     /* For each level (except not the global one),
  582.        a chain of BLOCK nodes for all the levels
  583.        that were entered and exited one level down.  */
  584.     tree blocks;
  585.  
  586.     /* The BLOCK node for this level, if one has been preallocated.
  587.        If 0, the BLOCK is allocated (if needed) when the level is popped.  */
  588.     tree this_block;
  589.  
  590.     /* The binding level which this one is contained in (inherits from).  */
  591.     struct binding_level *level_chain;
  592.  
  593.     /* Number of decls in `names' that have incomplete 
  594.        structure or union types.  */
  595.     unsigned short n_incomplete;
  596.  
  597.     /* 1 for the level that holds the parameters of a function.
  598.        2 for the level that holds a class declaration.
  599.        3 for levels that hold parameter declarations.  */
  600.     unsigned parm_flag : 4;
  601.  
  602.     /* 1 means make a BLOCK for this level regardless of all else.
  603.        2 for temporary binding contours created by the compiler.  */
  604.     unsigned keep : 3;
  605.  
  606.     /* Nonzero if this level "doesn't exist" for tags.  */
  607.     unsigned tag_transparent : 1;
  608.  
  609.     /* Nonzero if this level can safely have additional
  610.        cleanup-needing variables added to it.  */
  611.     unsigned more_cleanups_ok : 1;
  612.     unsigned have_cleanups : 1;
  613.  
  614.     /* Nonzero if this level can safely have additional
  615.        exception-raising statements added to it.  */
  616.     unsigned more_exceptions_ok : 1;
  617.     unsigned have_exceptions : 1;
  618.  
  619.     /* Nonzero if we should accept any name as an identifier in
  620.        this scope.  This happens in some template definitions.  */
  621.     unsigned accept_any : 1;
  622.  
  623.     /* Nonzero if this level is for completing a template class definition
  624.        inside a binding level that temporarily binds the parameters.  This
  625.        means that definitions here should not be popped off when unwinding
  626.        this binding level.  (Not actually implemented this way,
  627.        unfortunately.)  */
  628.     unsigned pseudo_global : 1;
  629.  
  630.     /* Two bits left for this word.  */
  631.  
  632. #if PARANOID
  633.     unsigned char depth;
  634. #endif
  635.   };
  636.  
  637. #define NULL_BINDING_LEVEL (struct binding_level *) NULL
  638.   
  639. /* The binding level currently in effect.  */
  640.  
  641. static struct binding_level *current_binding_level;
  642.  
  643. /* The binding level of the current class, if any.  */
  644.  
  645. static struct binding_level *class_binding_level;
  646.  
  647. /* A chain of binding_level structures awaiting reuse.  */
  648.  
  649. static struct binding_level *free_binding_level;
  650.  
  651. /* The outermost binding level, for names of file scope.
  652.    This is created when the compiler is started and exists
  653.    through the entire run.  */
  654.  
  655. static struct binding_level *global_binding_level;
  656.  
  657. /* Binding level structures are initialized by copying this one.  */
  658.  
  659. static struct binding_level clear_binding_level;
  660.  
  661. /* Nonzero means unconditionally make a BLOCK for the next level pushed.  */
  662.  
  663. static int keep_next_level_flag;
  664.  
  665. #if PARANOID
  666. /* Perform sanity checking on binding levels.  Normally not needed.  */
  667. void
  668. binding_levels_sane ()
  669. {
  670.   struct binding_level *b = current_binding_level;
  671.   static int n;
  672.   if (++n < 3)
  673.     return;
  674.   my_friendly_assert (global_binding_level != 0, 126);
  675.   my_friendly_assert (current_binding_level != 0, 127);
  676.   for (b = current_binding_level; b != global_binding_level; b = b->level_chain)
  677.     {
  678.       my_friendly_assert (b->level_chain != 0, 128);
  679.       my_friendly_assert (b->depth == 1 + b->level_chain->depth, 129);
  680.     }
  681.   if (class_binding_level)
  682.     for (b = class_binding_level;
  683.          b != global_binding_level && b != current_binding_level;
  684.          b = b->level_chain)
  685.     {
  686.       my_friendly_assert (b->level_chain != 0, 130);
  687.       my_friendly_assert (b->depth == 1 + b->level_chain->depth, 131);
  688.     }
  689.   my_friendly_assert (global_binding_level->depth == 0, 132);
  690.   my_friendly_assert (global_binding_level->level_chain == 0, 133);
  691.   return;
  692. }
  693.  
  694. #else
  695. #define binding_levels_sane() ((void)(1))
  696. #endif
  697.  
  698. #ifdef DEBUG_CP_BINDING_LEVELS
  699. int debug_bindings_indentation;
  700. #endif
  701.  
  702. static void
  703. #if !PARANOID && defined (__GNUC__)
  704. __inline
  705. #endif
  706. push_binding_level (newlevel, tag_transparent, keep)
  707.      struct binding_level *newlevel;
  708.      int tag_transparent, keep;
  709. {
  710.   binding_levels_sane();
  711.   /* Add this level to the front of the chain (stack) of levels that
  712.      are active.  */
  713. #ifdef DEBUG_CP_BINDING_LEVELS
  714.   indent_to (stderr, debug_bindings_indentation);
  715.   fprintf (stderr, "pushing binding level ");
  716.   fprintf (stderr, HOST_PTR_PRINTF, newlevel);
  717.   fprintf (stderr, "\n");
  718. #endif
  719.   *newlevel = clear_binding_level;
  720.   if (class_binding_level)
  721.     {
  722.       newlevel->level_chain = class_binding_level;
  723.       class_binding_level = 0;
  724.     }
  725.   else
  726.     {
  727.       newlevel->level_chain = current_binding_level;
  728.     }
  729.   current_binding_level = newlevel;
  730.   newlevel->tag_transparent = tag_transparent;
  731.   newlevel->more_cleanups_ok = 1;
  732.   newlevel->more_exceptions_ok = 1;
  733.   newlevel->keep = keep;
  734. #if PARANOID
  735.   newlevel->depth = (newlevel->level_chain
  736.              ? newlevel->level_chain->depth + 1
  737.              : 0);
  738. #endif
  739.   binding_levels_sane();
  740. }
  741.  
  742. static void
  743. #if !PARANOID && defined (__GNUC__)
  744. __inline
  745. #endif
  746. pop_binding_level ()
  747. {
  748.   binding_levels_sane();
  749. #ifdef DEBUG_CP_BINDING_LEVELS
  750.   indent_to (stderr, debug_bindings_indentation);
  751.   fprintf (stderr, "popping binding level ");
  752.   fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
  753.   fprintf (stderr, "\n");
  754. #endif
  755.   if (global_binding_level)
  756.     {
  757.       /* cannot pop a level, if there are none left to pop. */
  758.       if (current_binding_level == global_binding_level)
  759.     my_friendly_abort (123);
  760.     }
  761.   /* Pop the current level, and free the structure for reuse.  */
  762.   {
  763.     register struct binding_level *level = current_binding_level;
  764.     current_binding_level = current_binding_level->level_chain;
  765.     level->level_chain = free_binding_level;
  766. #ifdef DEBUG_CP_BINDING_LEVELS
  767.     memset (level, 0x69, sizeof (*level));
  768. #else
  769.     free_binding_level = level;
  770. #if PARANOID
  771.     level->depth = ~0;    /* ~0 assumes that the depth is unsigned. */
  772. #endif
  773. #endif
  774.     if (current_binding_level->parm_flag == 2)
  775.       {
  776.     class_binding_level = current_binding_level;
  777.     do
  778.       {
  779.         current_binding_level = current_binding_level->level_chain;
  780.       }
  781.     while (current_binding_level->parm_flag == 2);
  782.       }
  783.   }
  784.   binding_levels_sane();
  785. }
  786.  
  787. /* Nonzero if we are currently in the global binding level.  */
  788.  
  789. int
  790. global_bindings_p ()
  791. {
  792.   return current_binding_level == global_binding_level;
  793. }
  794.  
  795. void
  796. keep_next_level ()
  797. {
  798.   keep_next_level_flag = 1;
  799. }
  800.  
  801. /* Nonzero if the current level needs to have a BLOCK made.  */
  802.  
  803. int
  804. kept_level_p ()
  805. {
  806.   return (current_binding_level->blocks != 0
  807.       || current_binding_level->keep
  808.       || current_binding_level->names != 0
  809.       || (current_binding_level->tags != 0
  810.           && !current_binding_level->tag_transparent));
  811. }
  812.  
  813. /* Identify this binding level as a level of parameters.  */
  814.  
  815. void
  816. declare_parm_level ()
  817. {
  818.   current_binding_level->parm_flag = 1;
  819. }
  820.  
  821. /* Identify this binding level as a level of a default exception handler.  */
  822.  
  823. void
  824. declare_implicit_exception ()
  825. {
  826.   current_binding_level->parm_flag = 3;
  827. }
  828.  
  829. /* Nonzero if current binding contour contains expressions
  830.    that might raise exceptions.  */
  831.  
  832. int
  833. have_exceptions_p ()
  834. {
  835.   return current_binding_level->have_exceptions;
  836. }
  837.  
  838. void
  839. declare_uninstantiated_type_level ()
  840. {
  841.   current_binding_level->accept_any = 1;
  842. }
  843.  
  844. int
  845. uninstantiated_type_level_p ()
  846. {
  847.   return current_binding_level->accept_any;
  848. }
  849.  
  850. void
  851. declare_pseudo_global_level ()
  852. {
  853.   current_binding_level->pseudo_global = 1;
  854. }
  855.  
  856. int
  857. pseudo_global_level_p ()
  858. {
  859.   return current_binding_level->pseudo_global;
  860. }
  861.  
  862. /* Enter a new binding level.
  863.    If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
  864.    not for that of tags.  */
  865.  
  866. void
  867. pushlevel (tag_transparent)
  868.      int tag_transparent;
  869. {
  870.   register struct binding_level *newlevel = NULL_BINDING_LEVEL;
  871.  
  872. #ifdef DEBUG_CP_BINDING_LEVELS
  873.   indent_to (stderr, debug_bindings_indentation);
  874.   fprintf (stderr, "pushlevel");
  875.   debug_bindings_indentation += 4;
  876. #endif
  877.  
  878.   /* If this is the top level of a function,
  879.      just make sure that NAMED_LABELS is 0.
  880.      They should have been set to 0 at the end of the previous function.  */
  881.  
  882.   if (current_binding_level == global_binding_level)
  883.     my_friendly_assert (named_labels == NULL_TREE, 134);
  884.  
  885.   /* Reuse or create a struct for this binding level.  */
  886.  
  887.   if (free_binding_level)
  888.     {
  889.       newlevel = free_binding_level;
  890.       free_binding_level = free_binding_level->level_chain;
  891.     }
  892.   else
  893.     {
  894.       /* Create a new `struct binding_level'.  */
  895.       newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
  896.     }
  897.   push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
  898.   GNU_xref_start_scope (newlevel);
  899.   keep_next_level_flag = 0;
  900.  
  901. #ifdef DEBUG_CP_BINDING_LEVELS
  902.   debug_bindings_indentation -= 4;
  903. #endif
  904. }
  905.  
  906. void
  907. pushlevel_temporary (tag_transparent)
  908.      int tag_transparent;
  909. {
  910.   pushlevel (tag_transparent);
  911.   current_binding_level->keep = 2;
  912.   clear_last_expr ();
  913.  
  914.   /* Note we don't call push_momentary() here.  Otherwise, it would cause
  915.      cleanups to be allocated on the momentary obstack, and they will be
  916.      overwritten by the next statement.  */
  917.  
  918.   expand_start_bindings (0);
  919. }
  920.  
  921. /* Exit a binding level.
  922.    Pop the level off, and restore the state of the identifier-decl mappings
  923.    that were in effect when this level was entered.
  924.  
  925.    If KEEP == 1, this level had explicit declarations, so
  926.    and create a "block" (a BLOCK node) for the level
  927.    to record its declarations and subblocks for symbol table output.
  928.  
  929.    If KEEP == 2, this level's subblocks go to the front,
  930.    not the back of the current binding level.  This happens,
  931.    for instance, when code for constructors and destructors
  932.    need to generate code at the end of a function which must
  933.    be moved up to the front of the function.
  934.  
  935.    If FUNCTIONBODY is nonzero, this level is the body of a function,
  936.    so create a block as if KEEP were set and also clear out all
  937.    label names.
  938.  
  939.    If REVERSE is nonzero, reverse the order of decls before putting
  940.    them into the BLOCK.  */
  941.  
  942. tree
  943. poplevel (keep, reverse, functionbody)
  944.      int keep;
  945.      int reverse;
  946.      int functionbody;
  947. {
  948.   register tree link;
  949.   /* The chain of decls was accumulated in reverse order.
  950.      Put it into forward order, just for cleanliness.  */
  951.   tree decls;
  952.   int tmp = functionbody;
  953.   int implicit_try_block = current_binding_level->parm_flag == 3;
  954.   int real_functionbody = current_binding_level->keep == 2
  955.     ? ((functionbody = 0), tmp) : functionbody;
  956.   tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
  957.   tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
  958.   tree block = 0;
  959.   tree decl;
  960.   int block_previously_created;
  961.  
  962. #ifdef DEBUG_CP_BINDING_LEVELS
  963.   indent_to (stderr, debug_bindings_indentation);
  964.   fprintf (stderr, "poplevel");
  965.   debug_bindings_indentation += 4;
  966. #endif
  967.  
  968.   binding_levels_sane();
  969.   GNU_xref_end_scope (current_binding_level,
  970.               current_binding_level->level_chain,
  971.               current_binding_level->parm_flag,
  972.               current_binding_level->keep,
  973.               current_binding_level->tag_transparent);
  974.  
  975.   if (current_binding_level->keep == 1)
  976.     keep = 1;
  977.  
  978.   /* This warning is turned off because it causes warnings for
  979.      declarations like `extern struct foo *x'.  */
  980. #if 0
  981.   /* Warn about incomplete structure types in this level.  */
  982.   for (link = tags; link; link = TREE_CHAIN (link))
  983.     if (TYPE_SIZE (TREE_VALUE (link)) == 0)
  984.       {
  985.     tree type = TREE_VALUE (link);
  986.     char *errmsg;
  987.     switch (TREE_CODE (type))
  988.       {
  989.       case RECORD_TYPE:
  990.         errmsg = "`struct %s' incomplete in scope ending here";
  991.         break;
  992.       case UNION_TYPE:
  993.         errmsg = "`union %s' incomplete in scope ending here";
  994.         break;
  995.       case ENUMERAL_TYPE:
  996.         errmsg = "`enum %s' incomplete in scope ending here";
  997.         break;
  998.       }
  999.     if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  1000.       error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  1001.     else
  1002.       /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  1003.       error (errmsg, TYPE_NAME_STRING (type));
  1004.       }
  1005. #endif /* 0 */
  1006.  
  1007.   /* Get the decls in the order they were written.
  1008.      Usually current_binding_level->names is in reverse order.
  1009.      But parameter decls were previously put in forward order.  */
  1010.  
  1011.   if (reverse)
  1012.     current_binding_level->names
  1013.       = decls = nreverse (current_binding_level->names);
  1014.   else
  1015.     decls = current_binding_level->names;
  1016.  
  1017.   /* Output any nested inline functions within this block
  1018.      if they weren't already output.  */
  1019.  
  1020.   for (decl = decls; decl; decl = TREE_CHAIN (decl))
  1021.     if (TREE_CODE (decl) == FUNCTION_DECL
  1022.     && ! TREE_ASM_WRITTEN (decl)
  1023.     && DECL_INITIAL (decl) != 0
  1024.     && TREE_ADDRESSABLE (decl))
  1025.       output_inline_function (decl);
  1026.  
  1027.   /* If there were any declarations or structure tags in that level,
  1028.      or if this level is a function body,
  1029.      create a BLOCK to record them for the life of this function.  */
  1030.  
  1031.   block = 0;
  1032.   block_previously_created = (current_binding_level->this_block != 0);
  1033.   if (block_previously_created)
  1034.     block = current_binding_level->this_block;
  1035.   else if (keep == 1 || functionbody)
  1036.     block = make_node (BLOCK);
  1037.   if (block != 0)
  1038.     {
  1039.       BLOCK_VARS (block) = decls;
  1040.       BLOCK_TYPE_TAGS (block) = tags;
  1041.       BLOCK_SUBBLOCKS (block) = subblocks;
  1042.       remember_end_note (block);
  1043.     }
  1044.  
  1045.   /* In each subblock, record that this is its superior.  */
  1046.  
  1047.   if (keep >= 0)
  1048.     for (link = subblocks; link; link = TREE_CHAIN (link))
  1049.       BLOCK_SUPERCONTEXT (link) = block;
  1050.  
  1051.   /* Clear out the meanings of the local variables of this level.  */
  1052.  
  1053.   for (link = decls; link; link = TREE_CHAIN (link))
  1054.     {
  1055.       if (DECL_NAME (link) != 0)
  1056.     {
  1057.       /* If the ident. was used or addressed via a local extern decl,
  1058.          don't forget that fact.  */
  1059.       if (DECL_EXTERNAL (link))
  1060.         {
  1061.           if (TREE_USED (link))
  1062.         TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
  1063.           if (TREE_ADDRESSABLE (link))
  1064.         TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
  1065.         }
  1066.       IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
  1067.     }
  1068.     }
  1069.  
  1070.   /* Restore all name-meanings of the outer levels
  1071.      that were shadowed by this level.  */
  1072.  
  1073.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  1074.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1075.   for (link = current_binding_level->class_shadowed;
  1076.        link; link = TREE_CHAIN (link))
  1077.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1078.   for (link = current_binding_level->type_shadowed;
  1079.        link; link = TREE_CHAIN (link))
  1080.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1081.  
  1082.   /* If the level being exited is the top level of a function,
  1083.      check over all the labels.  */
  1084.  
  1085.   if (functionbody)
  1086.     {
  1087.       /* If this is the top level block of a function,
  1088.          the vars are the function's parameters.
  1089.          Don't leave them in the BLOCK because they are
  1090.          found in the FUNCTION_DECL instead.  */
  1091.  
  1092.       BLOCK_VARS (block) = 0;
  1093.  
  1094.       /* Clear out the definitions of all label names,
  1095.      since their scopes end here.  */
  1096.  
  1097.       for (link = named_labels; link; link = TREE_CHAIN (link))
  1098.     {
  1099.       register tree label = TREE_VALUE (link);
  1100.  
  1101.       if (DECL_INITIAL (label) == 0)
  1102.         {
  1103.           error_with_decl (label, "label `%s' used but not defined");
  1104.           /* Avoid crashing later.  */
  1105.           define_label (input_filename, 1, DECL_NAME (label));
  1106.         }
  1107.       else if (warn_unused && !TREE_USED (label))
  1108.         warning_with_decl (label, 
  1109.                    "label `%s' defined but not used");
  1110.       SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), 0);
  1111.  
  1112.           /* Put the labels into the "variables" of the
  1113.              top-level block, so debugger can see them.  */
  1114.           TREE_CHAIN (label) = BLOCK_VARS (block);
  1115.           BLOCK_VARS (block) = label;
  1116.     }
  1117.  
  1118.       named_labels = 0;
  1119.     }
  1120.  
  1121.   /* Any uses of undefined labels now operate under constraints
  1122.      of next binding contour.  */
  1123.   {
  1124.     struct binding_level *level_chain;
  1125.     level_chain = current_binding_level->level_chain;
  1126.     if (level_chain)
  1127.       {
  1128.     tree labels;
  1129.     for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
  1130.       if (TREE_TYPE (labels) == (tree)current_binding_level)
  1131.         {
  1132.           TREE_TYPE (labels) = (tree)level_chain;
  1133.           TREE_PURPOSE (labels) = level_chain->names;
  1134.         }
  1135.       }
  1136.   }
  1137.  
  1138.   tmp = current_binding_level->keep;
  1139.  
  1140.   pop_binding_level ();
  1141.   if (functionbody)
  1142.     DECL_INITIAL (current_function_decl) = block;
  1143.   else if (block)
  1144.     {
  1145.       if (!block_previously_created)
  1146.         current_binding_level->blocks
  1147.           = chainon (current_binding_level->blocks, block);
  1148.     }
  1149.   /* If we did not make a block for the level just exited,
  1150.      any blocks made for inner levels
  1151.      (since they cannot be recorded as subblocks in that level)
  1152.      must be carried forward so they will later become subblocks
  1153.      of something else.  */
  1154.   else if (subblocks)
  1155.     if (keep == 2)
  1156.       current_binding_level->blocks = chainon (subblocks, current_binding_level->blocks);
  1157.     else
  1158.       current_binding_level->blocks
  1159.         = chainon (current_binding_level->blocks, subblocks);
  1160.  
  1161.   /* Take care of compiler's internal binding structures.  */
  1162.   if (tmp == 2 && !implicit_try_block)
  1163.     {
  1164. #if 0
  1165.       /* We did not call push_momentary for this
  1166.      binding contour, so there is nothing to pop.  */
  1167.       pop_momentary ();
  1168. #endif
  1169.       expand_end_bindings (getdecls (), keep, 1);
  1170.       block = poplevel (keep, reverse, real_functionbody);
  1171.     }
  1172.   if (block)
  1173.     TREE_USED (block) = 1;
  1174.   binding_levels_sane();
  1175. #ifdef DEBUG_CP_BINDING_LEVELS
  1176.   debug_bindings_indentation -= 4;
  1177. #endif
  1178.   return block;
  1179. }
  1180.  
  1181. /* Delete the node BLOCK from the current binding level.
  1182.    This is used for the block inside a stmt expr ({...})
  1183.    so that the block can be reinserted where appropriate.  */
  1184.  
  1185. void
  1186. delete_block (block)
  1187.      tree block;
  1188. {
  1189.   tree t;
  1190.   if (current_binding_level->blocks == block)
  1191.     current_binding_level->blocks = TREE_CHAIN (block);
  1192.   for (t = current_binding_level->blocks; t;)
  1193.     {
  1194.       if (TREE_CHAIN (t) == block)
  1195.     TREE_CHAIN (t) = TREE_CHAIN (block);
  1196.       else
  1197.     t = TREE_CHAIN (t);
  1198.     }
  1199.   TREE_CHAIN (block) = NULL;
  1200.   /* Clear TREE_USED which is always set by poplevel.
  1201.      The flag is set again if insert_block is called.  */
  1202.   TREE_USED (block) = 0;
  1203. }
  1204.  
  1205. /* Insert BLOCK at the end of the list of subblocks of the
  1206.    current binding level.  This is used when a BIND_EXPR is expanded,
  1207.    to handle the BLOCK node inside the BIND_EXPR.  */
  1208.  
  1209. void
  1210. insert_block (block)
  1211.      tree block;
  1212. {
  1213.   TREE_USED (block) = 1;
  1214.   current_binding_level->blocks
  1215.     = chainon (current_binding_level->blocks, block);
  1216. }
  1217.  
  1218. /* Add BLOCK to the current list of blocks for this binding contour.  */
  1219. void
  1220. add_block_current_level (block)
  1221.      tree block;
  1222. {
  1223.   current_binding_level->blocks
  1224.     = chainon (current_binding_level->blocks, block);
  1225. }
  1226.  
  1227. /* Set the BLOCK node for the innermost scope
  1228.    (the one we are currently in).  */
  1229.  
  1230. void
  1231. set_block (block)
  1232.     register tree block;
  1233. {
  1234.   current_binding_level->this_block = block;
  1235. }
  1236.  
  1237. /* Do a pushlevel for class declarations.  */
  1238. void
  1239. pushlevel_class ()
  1240. {
  1241.   binding_levels_sane();
  1242. #ifdef DEBUG_CP_BINDING_LEVELS
  1243.   indent_to (stderr, debug_bindings_indentation);
  1244.   fprintf (stderr, "pushlevel_class");
  1245.   debug_bindings_indentation += 4;
  1246. #endif
  1247.   pushlevel (0);
  1248.   decl_stack = push_decl_level (decl_stack, &decl_obstack);
  1249.   class_binding_level = current_binding_level;
  1250.   class_binding_level->parm_flag = 2;
  1251.   do
  1252.     {
  1253.       current_binding_level = current_binding_level->level_chain;
  1254.     }
  1255.   while (current_binding_level->parm_flag == 2);
  1256.   binding_levels_sane();
  1257. #ifdef DEBUG_CP_BINDING_LEVELS
  1258.   debug_bindings_indentation -= 4;
  1259. #endif
  1260. }
  1261.  
  1262. /* ...and a poplevel for class declarations.  */
  1263. tree
  1264. poplevel_class ()
  1265. {
  1266.   register struct binding_level *level = class_binding_level;
  1267.   tree block = 0;
  1268.   tree shadowed;
  1269.  
  1270. #ifdef DEBUG_CP_BINDING_LEVELS
  1271.   indent_to (stderr, debug_bindings_indentation);
  1272.   fprintf (stderr, "poplevel_class");
  1273.   debug_bindings_indentation += 4;
  1274. #endif
  1275.   binding_levels_sane();
  1276.   if (level == 0)
  1277.     {
  1278.       while (current_binding_level && class_binding_level == 0)
  1279.     block = poplevel (0, 0, 0);
  1280.       if (current_binding_level == 0)
  1281.     fatal ("syntax error too serious");
  1282.       level = class_binding_level;
  1283.     }
  1284.   decl_stack = pop_decl_level (decl_stack);
  1285.   for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
  1286.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  1287.   for (shadowed = level->class_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
  1288.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  1289.   for (shadowed = level->type_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
  1290.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  1291.  
  1292.   GNU_xref_end_scope (class_binding_level,
  1293.               class_binding_level->level_chain,
  1294.               class_binding_level->parm_flag,
  1295.               class_binding_level->keep,
  1296.               class_binding_level->tag_transparent);
  1297.  
  1298.   class_binding_level = level->level_chain;
  1299.   if (class_binding_level->parm_flag != 2)
  1300.     class_binding_level = 0;
  1301.  
  1302. #ifdef DEBUG_CP_BINDING_LEVELS
  1303.   indent_to (stderr, debug_bindings_indentation);
  1304.   fprintf (stderr, "popping class binding level ");
  1305.   fprintf (stderr, HOST_PTR_PRINTF, level);
  1306.   fprintf (stderr, "\n");
  1307.   memset (level, 0x69, sizeof (*level));
  1308.   debug_bindings_indentation -= 4;
  1309. #else
  1310.   level->level_chain = free_binding_level;
  1311.   free_binding_level = level;
  1312. #endif
  1313.   binding_levels_sane();
  1314.  
  1315.   return block;
  1316. }
  1317.  
  1318. /* For debugging.  */
  1319. int no_print_functions = 0;
  1320. int no_print_builtins = 0;
  1321.  
  1322. void
  1323. print_binding_level (lvl)
  1324.      struct binding_level *lvl;
  1325. {
  1326.   tree t;
  1327.   int i = 0, len;
  1328.   fprintf (stderr, " blocks=");
  1329.   fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
  1330.   fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d",
  1331.        lvl->n_incomplete, lvl->parm_flag, lvl->keep);
  1332.   if (lvl->tag_transparent)
  1333.     fprintf (stderr, " tag-transparent");
  1334.   if (lvl->more_cleanups_ok)
  1335.     fprintf (stderr, " more-cleanups-ok");
  1336.   if (lvl->have_cleanups)
  1337.     fprintf (stderr, " have-cleanups");
  1338.   if (lvl->more_exceptions_ok)
  1339.     fprintf (stderr, " more-exceptions-ok");
  1340.   if (lvl->have_exceptions)
  1341.     fprintf (stderr, " have-exceptions");
  1342.   fprintf (stderr, "\n");
  1343.   if (lvl->names)
  1344.     {
  1345.       fprintf (stderr, " names:\t");
  1346.       /* We can probably fit 3 names to a line?  */
  1347.       for (t = lvl->names; t; t = TREE_CHAIN (t))
  1348.     {
  1349.       if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL)) 
  1350.         continue;
  1351.       if (no_print_builtins
  1352.           && (TREE_CODE(t) == TYPE_DECL)
  1353.           && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>")))
  1354.         continue;
  1355.  
  1356.       /* Function decls tend to have longer names.  */
  1357.       if (TREE_CODE (t) == FUNCTION_DECL)
  1358.         len = 3;
  1359.       else
  1360.         len = 2;
  1361.       i += len;
  1362.       if (i > 6)
  1363.         {
  1364.           fprintf (stderr, "\n\t");
  1365.           i = len;
  1366.         }
  1367.       print_node_brief (stderr, "", t, 0);
  1368.       if (TREE_CODE (t) == ERROR_MARK)
  1369.         break;
  1370.     }
  1371.       if (i)
  1372.         fprintf (stderr, "\n");
  1373.     }
  1374.   if (lvl->tags)
  1375.     {
  1376.       fprintf (stderr, " tags:\t");
  1377.       i = 0;
  1378.       for (t = lvl->tags; t; t = TREE_CHAIN (t))
  1379.     {
  1380.       if (TREE_PURPOSE (t) == NULL_TREE)
  1381.         len = 3;
  1382.       else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
  1383.         len = 2;
  1384.       else
  1385.         len = 4;
  1386.       i += len;
  1387.       if (i > 5)
  1388.         {
  1389.           fprintf (stderr, "\n\t");
  1390.           i = len;
  1391.         }
  1392.       if (TREE_PURPOSE (t) == NULL_TREE)
  1393.         {
  1394.           print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
  1395.           fprintf (stderr, ">");
  1396.         }
  1397.       else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
  1398.         print_node_brief (stderr, "", TREE_VALUE (t), 0);
  1399.       else
  1400.         {
  1401.           print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
  1402.           print_node_brief (stderr, "", TREE_VALUE (t), 0);
  1403.           fprintf (stderr, ">");
  1404.         }
  1405.     }
  1406.       if (i)
  1407.     fprintf (stderr, "\n");
  1408.     }
  1409.   if (lvl->shadowed)
  1410.     {
  1411.       fprintf (stderr, " shadowed:");
  1412.       for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
  1413.     {
  1414.       fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
  1415.     }
  1416.       fprintf (stderr, "\n");
  1417.     }
  1418.   if (lvl->class_shadowed)
  1419.     {
  1420.       fprintf (stderr, " class-shadowed:");
  1421.       for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
  1422.     {
  1423.       fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
  1424.     }
  1425.       fprintf (stderr, "\n");
  1426.     }
  1427.   if (lvl->type_shadowed)
  1428.     {
  1429.       fprintf (stderr, " type-shadowed:");
  1430.       for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
  1431.         {
  1432. #if 0
  1433.           fprintf (stderr, "\n\t");
  1434.           print_node_brief (stderr, "<", TREE_PURPOSE (t), 0);
  1435.           if (TREE_VALUE (t))
  1436.             print_node_brief (stderr, " ", TREE_VALUE (t), 0);
  1437.           else
  1438.             fprintf (stderr, " (none)");
  1439.           fprintf (stderr, ">");
  1440. #else
  1441.       fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
  1442. #endif
  1443.         }
  1444.       fprintf (stderr, "\n");
  1445.     }
  1446. }
  1447.  
  1448. void
  1449. print_other_binding_stack (stack)
  1450.      struct binding_level *stack;
  1451. {
  1452.   struct binding_level *level;
  1453.   for (level = stack; level != global_binding_level; level = level->level_chain)
  1454.     {
  1455.       fprintf (stderr, "binding level ");
  1456.       fprintf (stderr, HOST_PTR_PRINTF, level);
  1457.       fprintf (stderr, "\n");
  1458.       print_binding_level (level);
  1459.     }
  1460. }
  1461.  
  1462. void
  1463. print_binding_stack ()
  1464. {
  1465.   struct binding_level *b;
  1466.   fprintf (stderr, "current_binding_level=");
  1467.   fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
  1468.   fprintf (stderr, "\nclass_binding_level=");
  1469.   fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
  1470.   fprintf (stderr, "\nglobal_binding_level=");
  1471.   fprintf (stderr, HOST_PTR_PRINTF, global_binding_level);
  1472.   fprintf (stderr, "\n");
  1473.   if (class_binding_level)
  1474.     {
  1475.       for (b = class_binding_level; b; b = b->level_chain)
  1476.     if (b == current_binding_level)
  1477.       break;
  1478.       if (b)
  1479.     b = class_binding_level;
  1480.       else
  1481.     b = current_binding_level;
  1482.     }
  1483.   else
  1484.     b = current_binding_level;
  1485.   print_other_binding_stack (b);
  1486.   fprintf (stderr, "global:\n");
  1487.   print_binding_level (global_binding_level);
  1488. }
  1489.  
  1490. /* Subroutines for reverting temporarily to top-level for instantiation
  1491.    of templates and such.  We actually need to clear out the class- and
  1492.    local-value slots of all identifiers, so that only the global values
  1493.    are at all visible.  Simply setting current_binding_level to the global
  1494.    scope isn't enough, because more binding levels may be pushed.  */
  1495. struct saved_scope {
  1496.   struct binding_level *old_binding_level;
  1497.   tree old_bindings;
  1498.   struct saved_scope *prev;
  1499.   tree class_name, class_type, class_decl, function_decl;
  1500.   struct binding_level *class_bindings;
  1501. };
  1502. static struct saved_scope *current_saved_scope;
  1503. extern tree prev_class_type;
  1504.  
  1505. void
  1506. push_to_top_level ()
  1507. {
  1508.   struct saved_scope *s =
  1509.     (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
  1510.   struct binding_level *b = current_binding_level;
  1511.   tree old_bindings = NULL_TREE;
  1512.  
  1513. #ifdef DEBUG_CP_BINDING_LEVELS
  1514.   fprintf (stderr, "PUSH_TO_TOP_LEVEL\n");
  1515. #endif
  1516.  
  1517.   /* Have to include global_binding_level, because class-level decls
  1518.      aren't listed anywhere useful.  */
  1519.   for (; b; b = b->level_chain)
  1520.     {
  1521.       tree t;
  1522.       for (t = b->names; t; t = TREE_CHAIN (t))
  1523.     if (b != global_binding_level)
  1524.       {
  1525.         tree binding, t1, t2 = t;
  1526.         tree id = DECL_ASSEMBLER_NAME (t2);
  1527.  
  1528.         if (!id
  1529.         || (!IDENTIFIER_LOCAL_VALUE (id)
  1530.             && !IDENTIFIER_CLASS_VALUE (id)))
  1531.           continue;
  1532.  
  1533.         for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
  1534.           if (TREE_VEC_ELT (t1, 0) == id)
  1535.         goto skip_it;
  1536.         
  1537.         binding = make_tree_vec (4);
  1538.         if (id)
  1539.           {
  1540.         my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
  1541.         TREE_VEC_ELT (binding, 0) = id;
  1542.         TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
  1543.         TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
  1544.         TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
  1545.         IDENTIFIER_LOCAL_VALUE (id) = 0;
  1546.         IDENTIFIER_CLASS_VALUE (id) = 0;
  1547.         adjust_type_value (id);
  1548.           }
  1549.         TREE_CHAIN (binding) = old_bindings;
  1550.         old_bindings = binding;
  1551.         skip_it:
  1552.         ;
  1553.       }
  1554.       /* Unwind type-value slots back to top level.  */
  1555.       if (b != global_binding_level)
  1556.         for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
  1557.           SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
  1558.     }
  1559.  
  1560.   s->old_binding_level = current_binding_level;
  1561.   current_binding_level = global_binding_level;
  1562.  
  1563.   s->class_name = current_class_name;
  1564.   s->class_type = current_class_type;
  1565.   s->class_decl = current_class_decl;
  1566.   s->function_decl = current_function_decl;
  1567.   s->class_bindings = class_binding_level;
  1568.   current_class_name = current_class_type = current_class_decl = 0;
  1569.   current_function_decl = 0;
  1570.   class_binding_level = 0;
  1571.  
  1572.   s->prev = current_saved_scope;
  1573.   s->old_bindings = old_bindings;
  1574.   current_saved_scope = s;
  1575.   binding_levels_sane();
  1576. }
  1577.  
  1578. void
  1579. pop_from_top_level ()
  1580. {
  1581.   struct saved_scope *s = current_saved_scope;
  1582.   tree t;
  1583.  
  1584. #ifdef DEBUG_CP_BINDING_LEVELS
  1585.   fprintf (stderr, "POP_FROM_TOP_LEVEL\n");
  1586. #endif
  1587.  
  1588.   binding_levels_sane();
  1589.   current_binding_level = s->old_binding_level;
  1590.   current_saved_scope = s->prev;
  1591.   for (t = s->old_bindings; t; t = TREE_CHAIN (t))
  1592.     {
  1593.       tree id = TREE_VEC_ELT (t, 0);
  1594.       if (id)
  1595.     {
  1596.       IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
  1597.       IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
  1598.       IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
  1599.     }
  1600.     }
  1601.   current_class_name = s->class_name;
  1602.   current_class_type = s->class_type;
  1603.   current_class_decl = s->class_decl;
  1604.   if (current_class_type)
  1605.     C_C_D = CLASSTYPE_INST_VAR (current_class_type);
  1606.   else
  1607.     C_C_D = NULL_TREE;
  1608.   current_function_decl = s->function_decl;
  1609.   class_binding_level = s->class_bindings;
  1610.   free (s);
  1611.   binding_levels_sane();
  1612. }
  1613.  
  1614. /* Push a definition of struct, union or enum tag "name".
  1615.    "type" should be the type node.
  1616.    We assume that the tag "name" is not already defined.
  1617.  
  1618.    Note that the definition may really be just a forward reference.
  1619.    In that case, the TYPE_SIZE will be zero.
  1620.  
  1621.    C++ gratuitously puts all these tags in the name space. */
  1622.  
  1623. /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
  1624.    record the shadowed value for this binding contour.  TYPE is
  1625.    the type that ID maps to.  */
  1626. void
  1627. set_identifier_type_value (id, type)
  1628.      tree id;
  1629.      tree type;
  1630. {
  1631.   if (current_binding_level != global_binding_level)
  1632.     {
  1633.       tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
  1634.       current_binding_level->type_shadowed
  1635.     = tree_cons (id, old_type_value, current_binding_level->type_shadowed);
  1636.     }
  1637.   else if (class_binding_level)
  1638.     {
  1639.       tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
  1640.       class_binding_level->type_shadowed
  1641.     = tree_cons (id, old_type_value, class_binding_level->type_shadowed);
  1642.     }      
  1643.   SET_IDENTIFIER_TYPE_VALUE (id, type);
  1644. }
  1645.  
  1646. /*
  1647.  * local values can need to be shadowed too, but it only happens
  1648.  * explicitly from pushdecl, in support of nested enums.
  1649.  */
  1650. void
  1651. set_identifier_local_value (id, type)
  1652.      tree id;
  1653.      tree type;
  1654. {
  1655.   if (current_binding_level != global_binding_level)
  1656.     {
  1657.       tree old_local_value = IDENTIFIER_LOCAL_VALUE (id);
  1658.       current_binding_level->shadowed
  1659.     = tree_cons (id, old_local_value, current_binding_level->shadowed);
  1660.     }
  1661.   else if (class_binding_level)
  1662.     {
  1663.       tree old_local_value = IDENTIFIER_LOCAL_VALUE (id);
  1664.       class_binding_level->shadowed
  1665.     = tree_cons (id, old_local_value, class_binding_level->shadowed);
  1666.     }      
  1667.   IDENTIFIER_LOCAL_VALUE (id) = type;
  1668. }
  1669.  
  1670. /* Subroutine "set_nested_typename" builds the nested-typename of
  1671.    the type decl in question.  (Argument CLASSNAME can actually be
  1672.    a function as well, if that's the smallest containing scope.)  */
  1673.  
  1674. static void
  1675. set_nested_typename (decl, classname, name, type)
  1676.      tree decl, classname, name, type;
  1677. {
  1678.   my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136);
  1679.   if (classname != 0)
  1680.     {
  1681.       char *buf;
  1682.       my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137);
  1683.       my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138);
  1684.       buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
  1685.                  + IDENTIFIER_LENGTH (name));
  1686.       sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
  1687.            IDENTIFIER_POINTER (name));
  1688.       DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
  1689.       SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl), type);
  1690.     }
  1691.   else
  1692.     DECL_NESTED_TYPENAME (decl) = name;
  1693. }
  1694.  
  1695. #if 0 /* not yet, should get fixed properly later */
  1696. /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME.
  1697.    Other routines shouldn't use build_decl directly; they'll produce
  1698.    incorrect results with `-g' unless they duplicate this code.
  1699.  
  1700.    This is currently needed mainly for dbxout.c, but we can make
  1701.    use of it in cp-method.c later as well.  */
  1702. tree
  1703. make_type_decl (name, type)
  1704.      tree name, type;
  1705. {
  1706.   tree decl, id;
  1707.   decl = build_decl (TYPE_DECL, name, type);
  1708.   if (TYPE_NAME (type) == name)
  1709.     /* Class/union/enum definition, or a redundant typedef for same.  */
  1710.     {
  1711.       id = get_identifier (build_overload_name (type, 1, 1));
  1712.       DECL_ASSEMBLER_NAME (decl) = id;
  1713.     }
  1714.   else if (TYPE_NAME (type) != NULL_TREE)
  1715.     /* Explicit typedef, or implicit typedef for template expansion.  */
  1716.     DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
  1717.   else
  1718.     {
  1719.       /* Typedef for unnamed struct; some other situations.
  1720.      TYPE_NAME is null; what's right here?  */
  1721.     }
  1722.   return decl;
  1723. }
  1724.  
  1725. #endif
  1726. void
  1727. pushtag (name, type)
  1728.      tree name, type;
  1729. {
  1730.   register struct binding_level *b;
  1731.  
  1732.   if (class_binding_level)
  1733.     b = class_binding_level;
  1734.   else
  1735.     {
  1736.       b = current_binding_level;
  1737.       while (b->tag_transparent) b = b->level_chain;
  1738.     }
  1739.  
  1740.   if (b == global_binding_level)
  1741.     b->tags = perm_tree_cons (name, type, b->tags);
  1742.   else
  1743.     b->tags = saveable_tree_cons (name, type, b->tags);
  1744.  
  1745.   if (name)
  1746.     {
  1747.       /* Record the identifier as the type's name if it has none.  */
  1748.  
  1749.       if (TYPE_NAME (type) == 0)
  1750.         TYPE_NAME (type) = name;
  1751.       
  1752.       /* Do C++ gratuitous typedefing.  */
  1753.       if (IDENTIFIER_TYPE_VALUE (name) != type
  1754.       && (TREE_CODE (type) != RECORD_TYPE
  1755.           || class_binding_level == 0
  1756.           || !CLASSTYPE_DECLARED_EXCEPTION (type)))
  1757.         {
  1758.           register tree d;
  1759.       if (current_class_type == 0
  1760.           || TYPE_SIZE (current_class_type) != NULL_TREE)
  1761.         {
  1762.           if (current_lang_name == lang_name_cplusplus)
  1763.         d = lookup_nested_type (type, current_class_type ? TYPE_NAME (current_class_type) : NULL_TREE);
  1764.           else
  1765.         d = NULL_TREE;
  1766.  
  1767.           if (d == NULL_TREE)
  1768.         {
  1769. #if 0 /* not yet, should get fixed properly later */
  1770.           d = make_type_decl (name, type);
  1771.           DECL_ASSEMBLER_NAME (d) = get_identifier (build_overload_name (type, 1, 1));
  1772. #else
  1773.           d = build_decl (TYPE_DECL, name, type);
  1774.           DECL_ASSEMBLER_NAME (d) = get_identifier (build_overload_name (type, 1, 1));
  1775. #endif
  1776.           /* mark the binding layer marker as internal. (mrs) */
  1777.           DECL_SOURCE_LINE (d) = 0;
  1778.           set_identifier_type_value (name, type);
  1779.         }
  1780.           else
  1781.         d = TYPE_NAME (d);
  1782.  
  1783.           /* If it is anonymous, then we are called from pushdecl,
  1784.          and we don't want to infinitely recurse.  Also, if the
  1785.          name is already in scope, we don't want to push it
  1786.          again--pushdecl is only for pushing new decls.  */
  1787.           if (! ANON_AGGRNAME_P (name)
  1788.           && TYPE_NAME (type)
  1789.           && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
  1790.               || lookup_name (name, 1) != TYPE_NAME (type)))
  1791.         {
  1792.           if (class_binding_level)
  1793.             d = pushdecl_class_level (d);
  1794.           else
  1795.             d = pushdecl (d);
  1796.         }
  1797.         }
  1798.       else
  1799.         {
  1800.           /* Make nested declarations go into class-level scope.  */
  1801.           d = build_lang_field_decl (TYPE_DECL, name, type);
  1802.           set_identifier_type_value (name, type);
  1803.           d = pushdecl_class_level (d);
  1804.         }
  1805.       if (ANON_AGGRNAME_P (name))
  1806.         DECL_IGNORED_P (d) = 1;
  1807.       TYPE_NAME (type) = d;
  1808.  
  1809.       if ((current_class_type == NULL_TREE
  1810.            && current_function_decl == NULL_TREE)
  1811.           || current_lang_name != lang_name_cplusplus)
  1812.         /* Non-nested class.  */
  1813.         DECL_NESTED_TYPENAME (d) = name;
  1814.       else if (current_function_decl != NULL_TREE)
  1815.         {
  1816.           /* Function-nested class.  */
  1817.           set_nested_typename (d, DECL_ASSEMBLER_NAME (current_function_decl),
  1818.                    name, type);
  1819.           /* This builds the links for classes nested in fn scope.  */
  1820.           DECL_CONTEXT (d) = current_function_decl;
  1821.         }
  1822.       else if (TYPE_SIZE (current_class_type) == NULL_TREE)
  1823.         {
  1824.           /* Class-nested class.  */
  1825.           set_nested_typename (d, DECL_NESTED_TYPENAME (TYPE_NAME (current_class_type)),
  1826.                    name, type);
  1827.           /* This builds the links for classes nested in type scope.  */
  1828.           DECL_CONTEXT (d) = current_class_type;
  1829.           DECL_CLASS_CONTEXT (d) = current_class_type;
  1830.         }
  1831.         }
  1832.       if (b->parm_flag == 2)
  1833.     {
  1834.       TREE_NONLOCAL_FLAG (type) = 1;
  1835.       IDENTIFIER_CLASS_VALUE (name) = TYPE_NAME (type);
  1836.       if (TYPE_SIZE (current_class_type) == NULL_TREE)
  1837.         CLASSTYPE_TAGS (current_class_type) = b->tags;
  1838.     }
  1839.     }
  1840.  
  1841.   if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  1842.     /* Use the canonical TYPE_DECL for this node.  */
  1843.     TYPE_STUB_DECL (type) = TYPE_NAME (type);
  1844.   else
  1845.     {
  1846.       /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
  1847.      will be the tagged type we just added to the current
  1848.      binding level.  This fake NULL-named TYPE_DECL node helps
  1849.      dwarfout.c to know when it needs to output a
  1850.      representation of a tagged type, and it also gives us a
  1851.      convenient place to record the "scope start" address for
  1852.      the tagged type.  */
  1853.  
  1854. #if 0 /* not yet, should get fixed properly later */
  1855.       TYPE_STUB_DECL (type) = pushdecl (make_type_decl (NULL, type));
  1856. #else
  1857.       TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL, type));
  1858. #endif
  1859.     }
  1860. }
  1861.  
  1862. /* Counter used to create anonymous type names.  */
  1863. static int anon_cnt = 0;
  1864.  
  1865. /* Return an IDENTIFIER which can be used as a name for
  1866.    anonymous structs and unions.  */
  1867. tree
  1868. make_anon_name ()
  1869. {
  1870.   char buf[32];
  1871.  
  1872.   sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
  1873.   return get_identifier (buf);
  1874. }
  1875.  
  1876. /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
  1877.    This keeps dbxout from getting confused.  */
  1878. void
  1879. clear_anon_tags ()
  1880. {
  1881.   register struct binding_level *b;
  1882.   register tree tags;
  1883.   static int last_cnt = 0;
  1884.  
  1885.   /* Fast out if no new anon names were declared.  */
  1886.   if (last_cnt == anon_cnt)
  1887.     return;
  1888.  
  1889.   b = current_binding_level;
  1890.   while (b->tag_transparent)
  1891.     b = b->level_chain;
  1892.   tags = b->tags;
  1893.   while (tags)
  1894.     {
  1895.       /* A NULL purpose means we have already processed all tags
  1896.      from here to the end of the list.  */
  1897.       if (TREE_PURPOSE (tags) == NULL_TREE)
  1898.     break;
  1899.       if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
  1900.     TREE_PURPOSE (tags) = NULL_TREE;
  1901.       tags = TREE_CHAIN (tags);
  1902.     }
  1903.   last_cnt = anon_cnt;
  1904. }
  1905.  
  1906. /* Subroutine of duplicate_decls: return truthvalue of whether
  1907.    or not types of these decls match.  */
  1908. static int
  1909. decls_match (newdecl, olddecl)
  1910.      tree newdecl, olddecl;
  1911. {
  1912.   int types_match;
  1913.  
  1914.   if (TREE_CODE (newdecl) == FUNCTION_DECL && TREE_CODE (olddecl) == FUNCTION_DECL)
  1915.     {
  1916.       tree f1 = TREE_TYPE (newdecl);
  1917.       tree f2 = TREE_TYPE (olddecl);
  1918.       tree p1 = TYPE_ARG_TYPES (f1);
  1919.       tree p2 = TYPE_ARG_TYPES (f2);
  1920.  
  1921.       /* When we parse a static member function definition,
  1922.      we put together a FUNCTION_DECL which thinks its type
  1923.      is METHOD_TYPE.  Change that to FUNCTION_TYPE, and
  1924.      proceed.  */
  1925.       if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl))
  1926.     revert_static_member_fn (&f1, &newdecl, &p1);
  1927.       else if (TREE_CODE (f2) == METHOD_TYPE
  1928.            && DECL_STATIC_FUNCTION_P (newdecl))
  1929.     revert_static_member_fn (&f2, &olddecl, &p2);
  1930.  
  1931.       /* Here we must take care of the case where new default
  1932.      parameters are specified.  Also, warn if an old
  1933.      declaration becomes ambiguous because default
  1934.      parameters may cause the two to be ambiguous.  */
  1935.       if (TREE_CODE (f1) != TREE_CODE (f2))
  1936.     {
  1937.       if (TREE_CODE (f1) == OFFSET_TYPE)
  1938.         compiler_error_with_decl (newdecl, "`%s' redeclared as member function");
  1939.       else
  1940.         compiler_error_with_decl (newdecl, "`%s' redeclared as non-member function");
  1941.       return 0;
  1942.     }
  1943.  
  1944.       if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (f1)),
  1945.              TYPE_MAIN_VARIANT (TREE_TYPE (f2)), 1))
  1946.     types_match = compparms (p1, p2, 1);
  1947.       else types_match = 0;
  1948.     }
  1949.   else
  1950.     {
  1951.       if (TREE_TYPE (newdecl) == error_mark_node)
  1952.     types_match = TREE_TYPE (olddecl) == error_mark_node;
  1953.       else if (TREE_TYPE (olddecl) == NULL_TREE)
  1954.     types_match = TREE_TYPE (newdecl) == NULL_TREE;
  1955.       else
  1956.     types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1);
  1957.     }
  1958.  
  1959.   return types_match;
  1960. }
  1961.  
  1962. /* Handle when a new declaration NEWDECL has the same name as an old
  1963.    one OLDDECL in the same binding contour.  Prints an error message
  1964.    if appropriate.
  1965.  
  1966.    If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
  1967.    Otherwise, return 0.  */
  1968.  
  1969. static int
  1970. duplicate_decls (newdecl, olddecl)
  1971.      register tree newdecl, olddecl;
  1972. {
  1973.   extern struct obstack permanent_obstack;
  1974.   unsigned olddecl_uid = DECL_UID (olddecl);
  1975.   int olddecl_friend = 0, types_match;
  1976.   int new_defines_function;
  1977.   register unsigned saved_old_decl_uid;
  1978.   register int saved_old_decl_friend_p;
  1979.  
  1980.   if (TREE_CODE (olddecl) == TREE_LIST
  1981.       && TREE_CODE (newdecl) == FUNCTION_DECL)
  1982.     {
  1983.       /* If a new decl finds a list of old decls, then
  1984.      we assume that the new decl has C linkage, and
  1985.      that the old decls have C++ linkage.  In this case,
  1986.      we must look through the list to see whether
  1987.      there is an ambiguity or not.  */
  1988.       tree olddecls = olddecl;
  1989.  
  1990.       /* If the overload list is empty, just install the decl.  */
  1991.       if (TREE_VALUE (olddecls) == NULL_TREE)
  1992.     {
  1993.       TREE_VALUE (olddecls) = newdecl;
  1994.       return 1;
  1995.     }
  1996.  
  1997.       while (olddecls)
  1998.     {
  1999.       if (decls_match (newdecl, TREE_VALUE (olddecls)))
  2000.         {
  2001.           if (TREE_CODE (newdecl) == VAR_DECL)
  2002.         ;
  2003.           else if (DECL_LANGUAGE (newdecl)
  2004.                != DECL_LANGUAGE (TREE_VALUE (olddecls)))
  2005.         {
  2006.           error_with_decl (newdecl, "declaration of `%s' with different language linkage");
  2007.           error_with_decl (TREE_VALUE (olddecls), "previous declaration here");
  2008.         }
  2009.           types_match = 1;
  2010.           break;
  2011.         }
  2012.       olddecls = TREE_CHAIN (olddecls);
  2013.     }
  2014.       if (olddecls)
  2015.     olddecl = TREE_VALUE (olddecl);
  2016.       else
  2017.     return 1;
  2018.     }
  2019.   else
  2020.     {
  2021.       if (TREE_CODE (olddecl) != TREE_LIST)
  2022.     olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl);
  2023.       types_match = decls_match (newdecl, olddecl);
  2024.     }
  2025.  
  2026.   if ((TREE_TYPE (newdecl) && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
  2027.       || (TREE_TYPE (olddecl) && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
  2028.     types_match = 0;
  2029.  
  2030.   /* If this decl has linkage, and the old one does too, maybe no error.  */
  2031.   if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
  2032.     {
  2033.       error_with_decl (newdecl, "`%s' redeclared as different kind of symbol");
  2034.       if (TREE_CODE (olddecl) == TREE_LIST)
  2035.     olddecl = TREE_VALUE (olddecl);
  2036.       error_with_decl (olddecl, "previous declaration of `%s'");
  2037.  
  2038.       /* New decl is completely inconsistent with the old one =>
  2039.      tell caller to replace the old one.  */
  2040.  
  2041.       return 0;
  2042.     }
  2043.  
  2044.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2045.     {
  2046.       /* Now that functions must hold information normally held
  2047.      by field decls, there is extra work to do so that
  2048.      declaration information does not get destroyed during
  2049.      definition.  */
  2050.       if (DECL_VINDEX (olddecl))
  2051.     DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
  2052.       if (DECL_CONTEXT (olddecl))
  2053.     DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
  2054.       if (DECL_CLASS_CONTEXT (olddecl))
  2055.     DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
  2056. #ifdef SOS
  2057.       if (DECL_DINDEX (olddecl))
  2058.     DECL_DINDEX (newdecl) = DECL_DINDEX (newdecl);
  2059. #endif
  2060.       if (DECL_CHAIN (newdecl) == 0)
  2061.     DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
  2062.       if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
  2063.     DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
  2064.     }
  2065.  
  2066.   if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
  2067.       && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl)
  2068.     /* If -traditional, avoid error for redeclaring fcn
  2069.        after implicit decl.  */
  2070.     ;
  2071.   else if (TREE_CODE (olddecl) == FUNCTION_DECL
  2072.        && DECL_BUILT_IN (olddecl))
  2073.     {
  2074.       if (!types_match)
  2075.     {
  2076.       error_with_decl (newdecl, "declaration of `%s'");
  2077.       error_with_decl (olddecl, "conflicts with built-in declaration `%s'");
  2078.     }
  2079.     }
  2080.   else if (!types_match)
  2081.     {
  2082.       tree oldtype = TREE_TYPE (olddecl);
  2083.       tree newtype = TREE_TYPE (newdecl);
  2084.       int give_error = 0;
  2085.  
  2086.       /* Already complained about this, so don't do so again.  */
  2087.       if (current_class_type == NULL_TREE
  2088.       || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
  2089.     {
  2090.       give_error = 1;
  2091.       error_with_decl (newdecl, "conflicting types for `%s'");
  2092.     }
  2093.  
  2094.       /* Check for function type mismatch
  2095.      involving an empty arglist vs a nonempty one.  */
  2096.       if (TREE_CODE (olddecl) == FUNCTION_DECL
  2097.       && comptypes (TREE_TYPE (oldtype),
  2098.             TREE_TYPE (newtype), 1)
  2099.       && ((TYPE_ARG_TYPES (oldtype) == 0
  2100.            && DECL_INITIAL (olddecl) == 0)
  2101.           || (TYPE_ARG_TYPES (newtype) == 0
  2102.           && DECL_INITIAL (newdecl) == 0)))
  2103.     {
  2104.       /* Classify the problem further.  */
  2105.       register tree t = TYPE_ARG_TYPES (oldtype);
  2106.       if (t == 0)
  2107.         t = TYPE_ARG_TYPES (newtype);
  2108.       for (; t; t = TREE_CHAIN (t))
  2109.         {
  2110.           register tree type = TREE_VALUE (t);
  2111.  
  2112.           if (TREE_CHAIN (t) == 0 && type != void_type_node)
  2113.         {
  2114.           error ("A parameter list with an ellipsis can't match");
  2115.           error ("an empty parameter name list declaration.");
  2116.           break;
  2117.         }
  2118.  
  2119.           if (TYPE_MAIN_VARIANT (type) == float_type_node
  2120.           || C_PROMOTING_INTEGER_TYPE_P (type))
  2121.         {
  2122.           error ("An argument type that has a default promotion");
  2123.           error ("can't match an empty parameter name list declaration.");
  2124.           break;
  2125.         }
  2126.         }
  2127.     }
  2128.       if (give_error)
  2129.     error_with_decl (olddecl, "previous declaration of `%s'");
  2130.  
  2131.       /* There is one thing GNU C++ cannot tolerate: a constructor
  2132.      which takes the type of object being constructed.
  2133.      Farm that case out here.  */
  2134.       if (TREE_CODE (newdecl) == FUNCTION_DECL
  2135.       && DECL_CONSTRUCTOR_P (newdecl))
  2136.     {
  2137.       tree tmp = TREE_CHAIN (TYPE_ARG_TYPES (newtype));
  2138.  
  2139.       if (tmp != NULL_TREE
  2140.           && (TYPE_MAIN_VARIANT (TREE_VALUE (tmp))
  2141.           == TYPE_METHOD_BASETYPE (newtype)))
  2142.         {
  2143.           tree parm = TREE_CHAIN (DECL_ARGUMENTS (newdecl));
  2144.           tree argtypes
  2145.         = hash_tree_chain (build_reference_type (TREE_VALUE (tmp)),
  2146.                    TREE_CHAIN (tmp));
  2147.  
  2148.           DECL_ARG_TYPE (parm)
  2149.         = TREE_TYPE (parm)
  2150.           = TYPE_REFERENCE_TO (TREE_VALUE (tmp));
  2151.  
  2152.           TREE_TYPE (newdecl) = newtype
  2153.         = build_cplus_method_type (TYPE_METHOD_BASETYPE (newtype),
  2154.                        TREE_TYPE (newtype), argtypes);
  2155.           error ("constructor cannot take as argument the type being constructed");
  2156.           SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl), current_class_type);
  2157.         }
  2158.     }
  2159.     }
  2160.   else
  2161.     {
  2162.       char *errmsg = redeclaration_error_message (newdecl, olddecl);
  2163.       if (errmsg)
  2164.     {
  2165.       error_with_decl (newdecl, errmsg);
  2166.       if (DECL_NAME (olddecl) != NULL_TREE)
  2167.         error_with_decl (olddecl,
  2168.                  (DECL_INITIAL (olddecl)
  2169.                   && current_binding_level == global_binding_level)
  2170.                     ? "`%s' previously defined here"
  2171.                     : "`%s' previously declared here");
  2172.     }
  2173.       else if (TREE_CODE (olddecl) == FUNCTION_DECL
  2174.            && DECL_INITIAL (olddecl) != 0
  2175.            && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == 0
  2176.            && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0)
  2177.     {
  2178.       /* Prototype decl follows defn w/o prototype.  */
  2179.       warning_with_decl (newdecl, "prototype for `%s'");
  2180.       warning_with_decl (olddecl,
  2181.                  "follows non-prototype definition here");
  2182.     }
  2183.  
  2184.       /* These bits are logically part of the type.  */
  2185.       if (pedantic
  2186.       && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
  2187.           || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
  2188.     error_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl");
  2189.     }
  2190.  
  2191.   /* Deal with C++: must preserve virtual function table size.  */
  2192.   if (TREE_CODE (olddecl) == TYPE_DECL)
  2193.     {
  2194.       if (TYPE_LANG_SPECIFIC (TREE_TYPE (newdecl))
  2195.           && TYPE_LANG_SPECIFIC (TREE_TYPE (olddecl)))
  2196.     {
  2197.       CLASSTYPE_VSIZE (TREE_TYPE (newdecl))
  2198.         = CLASSTYPE_VSIZE (TREE_TYPE (olddecl));
  2199.       CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (newdecl))
  2200.         = CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (olddecl));
  2201.     }
  2202.       /* why assert here?  Just because debugging information is
  2203.      messed up? (mrs) */
  2204.       /* it happens on something like:
  2205.          typedef struct Thing {
  2206.                     Thing();
  2207.                 int     x;
  2208.         } Thing;
  2209.       */
  2210. #if 0
  2211.       my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl), 139);
  2212. #endif
  2213.     }
  2214.  
  2215.   /* Special handling ensues if new decl is a function definition.  */
  2216.   new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL
  2217.               && DECL_INITIAL (newdecl) != 0);
  2218.  
  2219.   /* Optionally warn about more than one declaration for the same name,
  2220.      but don't warn about a function declaration followed by a definition.  */
  2221.   if (warn_redundant_decls && DECL_SOURCE_LINE (olddecl) != 0
  2222.       && !(new_defines_function && DECL_INITIAL (olddecl) == 0))
  2223.     {
  2224.       warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope");
  2225.       warning_with_decl (olddecl, "previous declaration of `%s'");
  2226.     }
  2227.  
  2228.   /* Copy all the DECL_... slots specified in the new decl
  2229.      except for any that we copy here from the old type.  */
  2230.  
  2231.   if (types_match)
  2232.     {
  2233.       /* Automatically handles default parameters.  */
  2234.       tree oldtype = TREE_TYPE (olddecl);
  2235.       /* Merge the data types specified in the two decls.  */
  2236.       tree newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
  2237.  
  2238.       if (TREE_CODE (newdecl) == VAR_DECL)
  2239.     DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
  2240.       /* Do this after calling `common_type' so that default
  2241.      parameters don't confuse us.  */
  2242.       else if (TREE_CODE (newdecl) == FUNCTION_DECL
  2243.       && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
  2244.           != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
  2245.     {
  2246.       tree ctype = NULL_TREE;
  2247.       ctype = DECL_CLASS_CONTEXT (newdecl);
  2248.       TREE_TYPE (newdecl) = build_exception_variant (ctype, newtype,
  2249.                              TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
  2250.       TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype,
  2251.                              TYPE_RAISES_EXCEPTIONS (oldtype));
  2252.  
  2253.       if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
  2254.         {
  2255.           error_with_decl (newdecl, "declaration of `%s' raises different exceptions...");
  2256.           error_with_decl (olddecl, "...from previous declaration here");
  2257.         }
  2258.     }
  2259.       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
  2260.  
  2261.       /* Lay the type out, unless already done.  */
  2262.       if (oldtype != TREE_TYPE (newdecl))
  2263.     {
  2264.       if (TREE_TYPE (newdecl) != error_mark_node)
  2265.         layout_type (TREE_TYPE (newdecl));
  2266.       if (TREE_CODE (newdecl) != FUNCTION_DECL
  2267.           && TREE_CODE (newdecl) != TYPE_DECL
  2268.           && TREE_CODE (newdecl) != CONST_DECL)
  2269.         layout_decl (newdecl, 0);
  2270.     }
  2271.       else
  2272.     {
  2273.       /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
  2274.       DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
  2275.     }
  2276.  
  2277.       /* Merge the type qualifiers.  */
  2278.       if (TREE_READONLY (newdecl))
  2279.     TREE_READONLY (olddecl) = 1;
  2280.       if (TREE_THIS_VOLATILE (newdecl))
  2281.     TREE_THIS_VOLATILE (olddecl) = 1;
  2282.  
  2283.       /* Merge the initialization information.  */
  2284.       if (DECL_INITIAL (newdecl) == 0)
  2285.     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  2286.       /* Keep the old rtl since we can safely use it, unless it's the
  2287.      call to abort() used for abstract virtuals.  */
  2288.       if ((DECL_LANG_SPECIFIC (olddecl)
  2289.        && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
  2290.       || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
  2291.     DECL_RTL (newdecl) = DECL_RTL (olddecl);
  2292.     }
  2293.   /* If cannot merge, then use the new type and qualifiers,
  2294.      and don't preserve the old rtl.  */
  2295.   else
  2296.     {
  2297.       /* Clean out any memory we had of the old declaration.  */
  2298.       tree oldstatic = value_member (olddecl, static_aggregates);
  2299.       if (oldstatic)
  2300.     TREE_VALUE (oldstatic) = error_mark_node;
  2301.  
  2302.       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
  2303.       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
  2304.       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
  2305.       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
  2306.     }
  2307.  
  2308.   /* Merge the storage class information.  */
  2309.   if (DECL_EXTERNAL (newdecl))
  2310.     {
  2311.       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
  2312.       DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
  2313.  
  2314.       /* For functions, static overrides non-static.  */
  2315.       if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2316.     {
  2317.       TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
  2318.       /* This is since we don't automatically
  2319.          copy the attributes of NEWDECL into OLDDECL.  */
  2320.       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
  2321.       /* If this clears `static', clear it in the identifier too.  */
  2322.       if (! TREE_PUBLIC (olddecl))
  2323.         TREE_PUBLIC (DECL_ASSEMBLER_NAME (olddecl)) = 0;
  2324.     }
  2325.       else
  2326.     TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
  2327.     }
  2328.   else
  2329.     {
  2330.       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
  2331.       /* A `const' which was not declared `extern' and is
  2332.      in static storage is invisible.  */
  2333.       if (TREE_CODE (newdecl) == VAR_DECL
  2334.       && TREE_READONLY (newdecl) && TREE_STATIC (newdecl)
  2335.       && ! DECL_THIS_EXTERN (newdecl))
  2336.     TREE_PUBLIC (newdecl) = 0;
  2337.       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
  2338.     }
  2339.  
  2340.   /* If either decl says `inline', this fn is inline,
  2341.      unless its definition was passed already.  */
  2342.   if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == 0)
  2343.     DECL_INLINE (olddecl) = 1;
  2344.   DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
  2345.  
  2346.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2347.     {
  2348.       if (new_defines_function)
  2349.     /* If defining a function declared with other language
  2350.        linkage, use the previously declared language linkage.  */
  2351.     DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
  2352.       else
  2353.     {
  2354.       /* If redeclaring a builtin function, and not a definition,
  2355.          it stays built in.  */
  2356.       if (DECL_BUILT_IN (olddecl))
  2357.         {
  2358.           DECL_BUILT_IN (newdecl) = 1;
  2359.           DECL_SET_FUNCTION_CODE (newdecl, DECL_FUNCTION_CODE (olddecl));
  2360.           /* If we're keeping the built-in definition, keep the rtl,
  2361.          regardless of declaration matches.  */
  2362.           DECL_RTL (newdecl) = DECL_RTL (olddecl);
  2363.         }
  2364.       else
  2365.         DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
  2366.  
  2367.       DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
  2368.       if (DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))
  2369.         /* Previously saved insns go together with
  2370.            the function's previous definition.  */
  2371.         DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  2372.       /* Don't clear out the arguments if we're redefining a function.  */
  2373.       if (DECL_ARGUMENTS (olddecl))
  2374.         DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
  2375.     }
  2376.     }
  2377.  
  2378.   /* Now preserve various other info from the definition.  */
  2379.   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
  2380.   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
  2381.  
  2382.   /* Don't really know how much of the language-specific
  2383.      values we should copy from old to new.  */
  2384. #if 1
  2385.   if (DECL_LANG_SPECIFIC (olddecl))
  2386.     DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
  2387. #endif
  2388.  
  2389.   /* We are about to copy the contexts of newdecl into olddecl, so save a
  2390.      few tidbits of information from olddecl that we may need to restore
  2391.      after the copying takes place.  */
  2392.  
  2393.   saved_old_decl_uid = DECL_UID (olddecl);
  2394.   saved_old_decl_friend_p
  2395.     = DECL_LANG_SPECIFIC (olddecl) ? DECL_FRIEND_P (olddecl) : 0;
  2396.  
  2397.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2398.     {
  2399.       int function_size;
  2400.       struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
  2401.       struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
  2402.  
  2403.       function_size = sizeof (struct tree_decl);
  2404.  
  2405.       bcopy ((char *) newdecl + sizeof (struct tree_common),
  2406.          (char *) olddecl + sizeof (struct tree_common),
  2407.          function_size - sizeof (struct tree_common));
  2408.  
  2409.       if ((char *)newdecl + ((function_size + sizeof (struct lang_decl)
  2410.                  + obstack_alignment_mask (&permanent_obstack))
  2411.                  & ~ obstack_alignment_mask (&permanent_obstack))
  2412.       == obstack_next_free (&permanent_obstack))
  2413.     {
  2414.       DECL_MAIN_VARIANT (newdecl) = olddecl;
  2415.       DECL_LANG_SPECIFIC (olddecl) = ol;
  2416.       bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
  2417.  
  2418.       obstack_free (&permanent_obstack, newdecl);
  2419.     }
  2420.       else if (LANG_DECL_PERMANENT (ol))
  2421.     {
  2422.       if (DECL_MAIN_VARIANT (olddecl) == olddecl)
  2423.         {
  2424.           /* Save these lang_decls that would otherwise be lost.  */
  2425.           extern tree free_lang_decl_chain;
  2426.           tree free_lang_decl = (tree) ol;
  2427.           TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
  2428.           free_lang_decl_chain = free_lang_decl;
  2429.         }
  2430.       else
  2431.         {
  2432.           /* Storage leak.  */
  2433.         }
  2434.     }
  2435.     }
  2436.   else
  2437.     {
  2438.       bcopy ((char *) newdecl + sizeof (struct tree_common),
  2439.          (char *) olddecl + sizeof (struct tree_common),
  2440.          sizeof (struct tree_decl) - sizeof (struct tree_common)
  2441.          + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
  2442.     }
  2443.  
  2444.   DECL_UID (olddecl) = olddecl_uid;
  2445.   if (olddecl_friend)
  2446.     DECL_FRIEND_P (olddecl) = 1;
  2447.  
  2448.   /* Restore some pieces of information which were originally in olddecl.  */
  2449.  
  2450.   DECL_UID (olddecl) = saved_old_decl_uid;
  2451.   if (DECL_LANG_SPECIFIC (olddecl))
  2452.     DECL_FRIEND_P (olddecl) |= saved_old_decl_friend_p;
  2453.  
  2454.   return 1;
  2455. }
  2456.  
  2457. void
  2458. adjust_type_value (id)
  2459.      tree id;
  2460. {
  2461.   tree t;
  2462.  
  2463.   if (current_binding_level != global_binding_level)
  2464.     {
  2465.       if (current_binding_level != class_binding_level)
  2466.     {
  2467.       t = IDENTIFIER_LOCAL_VALUE (id);
  2468.       if (t && TREE_CODE (t) == TYPE_DECL)
  2469.         {
  2470.         set_it:
  2471.           SET_IDENTIFIER_TYPE_VALUE (id, TREE_TYPE (t));
  2472.           return;
  2473.         }
  2474.     }
  2475.       else
  2476.     my_friendly_abort (7);
  2477.  
  2478.       if (current_class_type)
  2479.     {
  2480.       t = IDENTIFIER_CLASS_VALUE (id);
  2481.       if (t && TREE_CODE (t) == TYPE_DECL)
  2482.         goto set_it;
  2483.     }
  2484.     }
  2485.  
  2486.   t = IDENTIFIER_GLOBAL_VALUE (id);
  2487.   if (t && TREE_CODE (t) == TYPE_DECL)
  2488.     goto set_it;
  2489.   if (t && TREE_CODE (t) == TEMPLATE_DECL)
  2490.     SET_IDENTIFIER_TYPE_VALUE (id, NULL_TREE);
  2491. }
  2492.  
  2493. /* Record a decl-node X as belonging to the current lexical scope.
  2494.    Check for errors (such as an incompatible declaration for the same
  2495.    name already seen in the same scope).
  2496.  
  2497.    Returns either X or an old decl for the same name.
  2498.    If an old decl is returned, it may have been smashed
  2499.    to agree with what X says.  */
  2500.  
  2501. tree
  2502. pushdecl (x)
  2503.      tree x;
  2504. {
  2505.   register tree t;
  2506. #if 0 /* not yet, should get fixed properly later */
  2507.   register tree name;
  2508. #else
  2509.   register tree name = DECL_ASSEMBLER_NAME (x);
  2510. #endif
  2511.   register struct binding_level *b = current_binding_level;
  2512.  
  2513. #if 0
  2514.   static int nglobals; int len;
  2515.  
  2516.   len = list_length (global_binding_level->names);
  2517.   if (len < nglobals)
  2518.     my_friendly_abort (8);
  2519.   else if (len > nglobals)
  2520.     nglobals = len;
  2521. #endif
  2522.  
  2523.   /* Don't change DECL_CONTEXT of virtual methods.  */
  2524.   if (x != current_function_decl
  2525.       && (TREE_CODE (x) != FUNCTION_DECL
  2526.       || !DECL_VIRTUAL_P (x)))
  2527.     DECL_CONTEXT (x) = current_function_decl;
  2528.  
  2529. #if 0 /* not yet, should get fixed properly later */
  2530.   /* For functions and class static data, we currently look up the encoded
  2531.      form of the name.  For types, we want the real name.  The former will
  2532.      probably be changed soon, according to MDT.  */
  2533.   if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
  2534.     name = DECL_ASSEMBLER_NAME (x);
  2535.   else
  2536.     name = DECL_NAME (x);
  2537. #else
  2538.   /* Type are looked up using the DECL_NAME, as that is what the rest of the
  2539.      compiler wants to use. */
  2540.   if (TREE_CODE (x) == TYPE_DECL)
  2541.     name = DECL_NAME (x);
  2542. #endif
  2543.  
  2544.   if (name)
  2545.     {
  2546.       char *file;
  2547.       int line;
  2548.  
  2549.       t = lookup_name_current_level (name);
  2550.       if (t != 0 && t == error_mark_node)
  2551.     /* error_mark_node is 0 for a while during initialization!  */
  2552.     {
  2553.       t = 0;
  2554.       error_with_decl (x, "`%s' used prior to declaration");
  2555.     }
  2556.  
  2557.       if (t != 0)
  2558.     {
  2559.       if (TREE_CODE (t) == PARM_DECL)
  2560.         {
  2561.           if (DECL_CONTEXT (t) == NULL_TREE)
  2562.         fatal ("parse errors have confused me too much");
  2563.         }
  2564.       file = DECL_SOURCE_FILE (t);
  2565.       line = DECL_SOURCE_LINE (t);
  2566.     }
  2567.  
  2568.       if (t != 0 && TREE_CODE (t) != TREE_CODE (x))
  2569.     {
  2570.       if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (x) == TYPE_DECL)
  2571.         {
  2572.           /* We do nothing special here, because C++ does such nasty
  2573.          things with TYPE_DECLs.  Instead, just let the TYPE_DECL
  2574.          get shadowed, and know that if we need to find a TYPE_DECL
  2575.          for a given name, we can look in the IDENTIFIER_TYPE_VALUE
  2576.          slot of the identifier.  */
  2577.           ;
  2578.         }
  2579.       else if (duplicate_decls (x, t))
  2580.         return t;
  2581.     }
  2582.       else if (t != 0 && duplicate_decls (x, t))
  2583.     {
  2584.       /* If this decl is `static' and an `extern' was seen previously,
  2585.          that is erroneous.  But don't complain if -traditional,
  2586.          since traditional compilers don't complain.
  2587.  
  2588.          Note that this does not apply to the C++ case of declaring
  2589.          a variable `extern const' and then later `const'.  */
  2590.       if (!flag_traditional && TREE_PUBLIC (name)
  2591.           && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x) && ! DECL_INLINE (x))
  2592.         {
  2593.           /* Due to interference in memory reclamation (X may be
  2594.          obstack-deallocated at this point), we must guard against
  2595.          one really special case.  */
  2596.           if (current_function_decl == x)
  2597.         current_function_decl = t;
  2598.           if (IDENTIFIER_IMPLICIT_DECL (name))
  2599.         warning ("`%s' was declared implicitly `extern' and later `static'",
  2600.              lang_printable_name (t));
  2601.           else
  2602.         warning ("`%s' was declared `extern' and later `static'",
  2603.              lang_printable_name (t));
  2604.           warning_with_file_and_line (file, line,
  2605.                       "previous declaration of `%s'",
  2606.                       lang_printable_name (t));
  2607.         }
  2608.       return t;
  2609.     }
  2610.  
  2611.       /* If declaring a type as a typedef, and the type has no known
  2612.      typedef name, install this TYPE_DECL as its typedef name.
  2613.  
  2614.      C++: If it had an anonymous aggregate or enum name,
  2615.      give it a `better' one.  */
  2616.       if (TREE_CODE (x) == TYPE_DECL)
  2617.     {
  2618.       tree name = TYPE_NAME (TREE_TYPE (x));
  2619.  
  2620.       if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
  2621.         {
  2622.           /* If these are different names, and we're at the global
  2623.          binding level, make two equivalent definitions.  */
  2624.               name = x;
  2625.               if (global_bindings_p ())
  2626.                 TYPE_NAME (TREE_TYPE (x)) = x;
  2627.         }
  2628.       else
  2629.         {
  2630.           tree tname = DECL_NAME (name);
  2631.           if (global_bindings_p () && ANON_AGGRNAME_P (tname))
  2632.         {
  2633.           /* do gratuitous C++ typedefing, and make sure that
  2634.              we access this type either through TREE_TYPE field
  2635.              or via the tags list.  */
  2636.           TYPE_NAME (TREE_TYPE (x)) = x;
  2637.           pushtag (tname, TREE_TYPE (x));
  2638.         }
  2639.         }
  2640.       my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140);
  2641.       if (DECL_NAME (name) && !DECL_NESTED_TYPENAME (name))
  2642.         set_nested_typename (x, current_class_name, DECL_NAME (name),
  2643.                  TREE_TYPE (x));
  2644.       if (TYPE_NAME (TREE_TYPE (x)) && TYPE_IDENTIFIER (TREE_TYPE (x)))
  2645.             set_identifier_type_value (DECL_NAME (x), TREE_TYPE (x));
  2646. /* was using TYPE_IDENTIFIER (TREE_TYPE (x)) */
  2647.     }
  2648.  
  2649.       /* Multiple external decls of the same identifier ought to match.  */
  2650.  
  2651.       if (DECL_EXTERNAL (x) && IDENTIFIER_GLOBAL_VALUE (name) != 0
  2652.       && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
  2653.           || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name)))
  2654.       /* We get warnings about inline functions where they are defined.
  2655.          Avoid duplicate warnings where they are used.  */
  2656.       && !DECL_INLINE (x))
  2657.     {
  2658.       if (! comptypes (TREE_TYPE (x),
  2659.                TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)), 1))
  2660.         {
  2661.           warning_with_decl (x,
  2662.                  "type mismatch with previous external decl");
  2663.           warning_with_decl (IDENTIFIER_GLOBAL_VALUE (name),
  2664.                  "previous external decl of `%s'");
  2665.         }
  2666.     }
  2667.  
  2668.       /* In PCC-compatibility mode, extern decls of vars with no current decl
  2669.      take effect at top level no matter where they are.  */
  2670.       if (flag_traditional && DECL_EXTERNAL (x)
  2671.       && lookup_name (name, 0) == 0)
  2672.     b = global_binding_level;
  2673.  
  2674.       /* This name is new in its binding level.
  2675.      Install the new declaration and return it.  */
  2676.       if (b == global_binding_level)
  2677.     {
  2678.       /* Install a global value.  */
  2679.  
  2680.       /* Rule for VAR_DECLs, but not for other kinds of _DECLs:
  2681.          A `const' which was not declared `extern' is invisible.  */
  2682.       if (TREE_CODE (x) == VAR_DECL
  2683.           && TREE_READONLY (x) && ! DECL_THIS_EXTERN (x))
  2684.         TREE_PUBLIC (x) = 0;
  2685.  
  2686.       /* If the first global decl has external linkage,
  2687.          warn if we later see static one.  */
  2688.       if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x))
  2689.         TREE_PUBLIC (name) = 1;
  2690.  
  2691.       /* Don't install a TYPE_DECL if we already have another
  2692.          sort of _DECL with that name.  */
  2693.       if (TREE_CODE (x) != TYPE_DECL
  2694.           || t == NULL_TREE
  2695.           || TREE_CODE (t) == TYPE_DECL)
  2696. #if 0
  2697.         /* This has not be thoroughly tested yet. */
  2698.         /* It allows better dwarf debugging. */
  2699.         IDENTIFIER_GLOBAL_VALUE (name)
  2700.           = TREE_CODE_CLASS (TREE_CODE (x)) == 'd'
  2701.         ? x : build_decl (TYPE_DECL, NULL, TREE_TYPE (x));
  2702. #else
  2703.         IDENTIFIER_GLOBAL_VALUE (name) = x;
  2704. #endif
  2705.  
  2706.       /* Don't forget if the function was used via an implicit decl.  */
  2707.       if (IDENTIFIER_IMPLICIT_DECL (name)
  2708.           && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
  2709.         TREE_USED (x) = 1;
  2710.  
  2711.       /* Don't forget if its address was taken in that way.  */
  2712.       if (IDENTIFIER_IMPLICIT_DECL (name)
  2713.           && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
  2714.         TREE_ADDRESSABLE (x) = 1;
  2715.  
  2716.       /* Warn about mismatches against previous implicit decl.  */
  2717.       if (IDENTIFIER_IMPLICIT_DECL (name) != 0
  2718.           /* If this real decl matches the implicit, don't complain.  */
  2719.           && ! (TREE_CODE (x) == FUNCTION_DECL
  2720.             && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
  2721.         warning ("`%s' was previously implicitly declared to return `int'",
  2722.              lang_printable_name (x));
  2723.  
  2724.       /* If this decl is `static' and an `extern' was seen previously,
  2725.          that is erroneous.  Don't do this for TYPE_DECLs.  */
  2726.       if (TREE_PUBLIC (name)
  2727.           && TREE_CODE (x) != TYPE_DECL
  2728.           && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x))
  2729.         {
  2730.           if (IDENTIFIER_IMPLICIT_DECL (name))
  2731.         warning ("`%s' was declared implicitly `extern' and later `static'",
  2732.              lang_printable_name (x));
  2733.           else
  2734.         warning ("`%s' was declared `extern' and later `static'",
  2735.              lang_printable_name (x));
  2736.         }
  2737.     }
  2738.       else
  2739.     {
  2740.       /* Here to install a non-global value.  */
  2741.       tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
  2742.       tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
  2743.       set_identifier_local_value (name, x);
  2744.  
  2745.       /* If this is an extern function declaration, see if we
  2746.          have a global definition or declaration for the function.  */
  2747.       if (oldlocal == 0
  2748.           && DECL_EXTERNAL (x) && !DECL_INLINE (x)
  2749.           && oldglobal != 0
  2750.           && TREE_CODE (x) == FUNCTION_DECL
  2751.           && TREE_CODE (oldglobal) == FUNCTION_DECL)
  2752.         {
  2753.           /* We have one.  Their types must agree.  */
  2754.           if (! comptypes (TREE_TYPE (x), TREE_TYPE (oldglobal), 1))
  2755.         warning_with_decl (x, "extern declaration of `%s' doesn't match global one");
  2756.           else
  2757.         {
  2758.           /* Inner extern decl is inline if global one is.
  2759.              Copy enough to really inline it.  */
  2760.           if (DECL_INLINE (oldglobal))
  2761.             {
  2762.               DECL_INLINE (x) = DECL_INLINE (oldglobal);
  2763.               DECL_INITIAL (x) = (current_function_decl == oldglobal
  2764.                       ? 0 : DECL_INITIAL (oldglobal));
  2765.               DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal);
  2766.               DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal);
  2767.               DECL_RESULT (x) = DECL_RESULT (oldglobal);
  2768.               TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal);
  2769.               DECL_ABSTRACT_ORIGIN (x) = oldglobal;
  2770.             }
  2771.           /* Inner extern decl is built-in if global one is.  */
  2772.           if (DECL_BUILT_IN (oldglobal))
  2773.             {
  2774.               DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal);
  2775.               DECL_SET_FUNCTION_CODE (x, DECL_FUNCTION_CODE (oldglobal));
  2776.             }
  2777.           /* Keep the arg types from a file-scope fcn defn.  */
  2778.           if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0
  2779.               && DECL_INITIAL (oldglobal)
  2780.               && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0)
  2781.             TREE_TYPE (x) = TREE_TYPE (oldglobal);
  2782.         }
  2783.         }
  2784.       /* If we have a local external declaration,
  2785.          and no file-scope declaration has yet been seen,
  2786.          then if we later have a file-scope decl it must not be static.  */
  2787.       if (oldlocal == 0
  2788.           && oldglobal == 0
  2789.           && DECL_EXTERNAL (x)
  2790.           && TREE_PUBLIC (x))
  2791.         {
  2792.           TREE_PUBLIC (name) = 1;
  2793.         }
  2794.  
  2795.       if (DECL_FROM_INLINE (x))
  2796.         /* Inline decls shadow nothing.  */;
  2797.  
  2798.       /* Warn if shadowing an argument at the top level of the body.  */
  2799.       else if (oldlocal != 0 && !DECL_EXTERNAL (x)
  2800.           && TREE_CODE (oldlocal) == PARM_DECL
  2801.           && TREE_CODE (x) != PARM_DECL)
  2802.         {
  2803.           /* Go to where the parms should be and see if we
  2804.          find them there.  */
  2805.           struct binding_level *b = current_binding_level->level_chain;
  2806.  
  2807.           if (cleanup_label)
  2808.         b = b->level_chain;
  2809.  
  2810.           if (b->parm_flag == 1)
  2811.         warning ("declaration of `%s' shadows a parameter",
  2812.              IDENTIFIER_POINTER (name));
  2813.         }
  2814.       /* Maybe warn if shadowing something else.  */
  2815.       else if (warn_shadow && !DECL_EXTERNAL (x)
  2816.            /* No shadow warnings for internally generated vars.  */
  2817.            && DECL_SOURCE_LINE (x) != 0
  2818.            /* No shadow warnings for vars made for inlining.  */
  2819.            && ! DECL_FROM_INLINE (x))
  2820.         {
  2821.           char *warnstring = 0;
  2822.  
  2823.           if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
  2824.         warnstring = "declaration of `%s' shadows a parameter";
  2825.           else if (IDENTIFIER_CLASS_VALUE (name) != 0)
  2826.         warnstring = "declaration of `%s' shadows a member of `this'";
  2827.           else if (oldlocal != 0)
  2828.         warnstring = "declaration of `%s' shadows previous local";
  2829.           else if (oldglobal != 0)
  2830.         warnstring = "declaration of `%s' shadows global declaration";
  2831.  
  2832.           if (warnstring)
  2833.         warning (warnstring, IDENTIFIER_POINTER (name));
  2834.         }
  2835.  
  2836.       /* If storing a local value, there may already be one (inherited).
  2837.          If so, record it for restoration when this binding level ends.  */
  2838.       if (oldlocal != 0)
  2839.         b->shadowed = tree_cons (name, oldlocal, b->shadowed);
  2840.     }
  2841.  
  2842.       /* Keep count of variables in this level with incomplete type.  */
  2843.       if (TREE_CODE (x) != TEMPLATE_DECL
  2844.       && TREE_CODE (x) != CPLUS_CATCH_DECL
  2845.       && TYPE_SIZE (TREE_TYPE (x)) == 0
  2846.       && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
  2847.     {
  2848.       if (++b->n_incomplete == 0)
  2849.         error ("too many incomplete variables at this point");
  2850.     }
  2851.     }
  2852.  
  2853.   if (TREE_CODE (x) == TYPE_DECL && name != NULL_TREE)
  2854.     {
  2855.       adjust_type_value (name);
  2856.       if (current_class_name)
  2857.     {
  2858.       if (!DECL_NESTED_TYPENAME (x))
  2859.         set_nested_typename (x, current_class_name, DECL_NAME (x),
  2860.                  TREE_TYPE (x));
  2861.       adjust_type_value (DECL_NESTED_TYPENAME (x));
  2862.     }
  2863.     }
  2864.  
  2865.   /* Put decls on list in reverse order.
  2866.      We will reverse them later if necessary.  */
  2867.   TREE_CHAIN (x) = b->names;
  2868.   b->names = x;
  2869.   if (! (b != global_binding_level || TREE_PERMANENT (x)))
  2870.     my_friendly_abort (124);
  2871.  
  2872.   return x;
  2873. }
  2874.  
  2875. #ifdef MPW
  2876. #pragma segment CPDECL01
  2877. #endif
  2878.  
  2879. /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
  2880.    if appropriate.  */
  2881. tree
  2882. pushdecl_top_level (x)
  2883.      tree x;
  2884. {
  2885.   register tree t;
  2886.   register struct binding_level *b = current_binding_level;
  2887.  
  2888.   current_binding_level = global_binding_level;
  2889.   t = pushdecl (x);
  2890.   current_binding_level = b;
  2891.   if (class_binding_level)
  2892.     b = class_binding_level;
  2893.   /* Now, the type_shadowed stack may screw us.  Munge it so it does
  2894.      what we want.  */
  2895.   if (TREE_CODE (x) == TYPE_DECL)
  2896.     {
  2897.       tree name = DECL_NAME (x);
  2898.       tree newval;
  2899.       tree *ptr = 0;
  2900.       for (; b != global_binding_level; b = b->level_chain)
  2901.         {
  2902.           tree shadowed = b->type_shadowed;
  2903.           for (; shadowed; shadowed = TREE_CHAIN (shadowed))
  2904.             if (TREE_PURPOSE (shadowed) == name)
  2905.               {
  2906.         ptr = &TREE_VALUE (shadowed);
  2907.         /* Can't break out of the loop here because sometimes
  2908.            a binding level will have duplicate bindings for
  2909.            PT names.  It's gross, but I haven't time to fix it.  */
  2910.               }
  2911.         }
  2912.       newval = TREE_TYPE (x);
  2913.       if (ptr == 0)
  2914.         {
  2915.           /* @@ This shouldn't be needed.  My test case "zstring.cc" trips
  2916.              up here if this is changed to an assertion.  --KR  */
  2917.       SET_IDENTIFIER_TYPE_VALUE (name, newval);
  2918.     }
  2919.       else
  2920.         {
  2921. #if 0
  2922.       /* Disabled this 11/10/92, since there are many cases which
  2923.          behave just fine when *ptr doesn't satisfy either of these.
  2924.          For example, nested classes declared as friends of their enclosing
  2925.          class will not meet this criteria.  (bpk) */
  2926.       my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141);
  2927. #endif
  2928.       *ptr = newval;
  2929.         }
  2930.     }
  2931.   return t;
  2932. }
  2933.  
  2934. /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
  2935.    if appropriate.  */
  2936. void
  2937. push_overloaded_decl_top_level (x, forget)
  2938.      tree x;
  2939.      int forget;
  2940. {
  2941.   struct binding_level *b = current_binding_level;
  2942.  
  2943.   current_binding_level = global_binding_level;
  2944.   push_overloaded_decl (x, forget);
  2945.   current_binding_level = b;
  2946. }
  2947.  
  2948. /* Make the declaration of X appear in CLASS scope.  */
  2949. tree
  2950. pushdecl_class_level (x)
  2951.      tree x;
  2952. {
  2953.   /* Don't use DECL_ASSEMBLER_NAME here!  Everything that looks in class
  2954.      scope looks for the pre-mangled name.  */
  2955.   register tree name = DECL_NAME (x);
  2956.  
  2957.   if (name)
  2958.     {
  2959.       tree oldclass = IDENTIFIER_CLASS_VALUE (name);
  2960.       if (oldclass)
  2961.     class_binding_level->class_shadowed
  2962.       = tree_cons (name, oldclass, class_binding_level->class_shadowed);
  2963.       IDENTIFIER_CLASS_VALUE (name) = x;
  2964.       obstack_ptr_grow (&decl_obstack, x);
  2965.       if (TREE_CODE (x) == TYPE_DECL && !DECL_NESTED_TYPENAME (x))
  2966.     set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
  2967.     }
  2968.   return x;
  2969. }
  2970.  
  2971. /* Tell caller how to interpret a TREE_LIST which contains
  2972.    chains of FUNCTION_DECLS.  */
  2973. int
  2974. overloaded_globals_p (list)
  2975.      tree list;
  2976. {
  2977.   my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142);
  2978.  
  2979.   /* Don't commit caller to seeing them as globals.  */
  2980.   if (TREE_NONLOCAL_FLAG (list))
  2981.     return -1;
  2982.   /* Do commit caller to seeing them as globals.  */
  2983.   if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
  2984.     return 1;
  2985.   /* Do commit caller to not seeing them as globals.  */
  2986.   return 0;
  2987. }
  2988.  
  2989. /* DECL is a FUNCTION_DECL which may have other definitions already in place.
  2990.    We get around this by making IDENTIFIER_GLOBAL_VALUE (DECL_NAME (DECL))
  2991.    point to a list of all the things that want to be referenced by that name.
  2992.    It is then up to the users of that name to decide what to do with that
  2993.    list.
  2994.  
  2995.    DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
  2996.    slot.  It is dealt with the same way.
  2997.  
  2998.    The value returned may be a previous declaration if we guessed wrong
  2999.    about what language DECL should belong to (C or C++).  Otherwise,
  3000.    it's always DECL (and never something that's not a _DECL).  */
  3001. tree
  3002. push_overloaded_decl (decl, forgettable)
  3003.      tree decl;
  3004.      int forgettable;
  3005. {
  3006.   tree orig_name = DECL_NAME (decl);
  3007.   tree glob = IDENTIFIER_GLOBAL_VALUE (orig_name);
  3008.  
  3009.   DECL_OVERLOADED (decl) = 1;
  3010.   if (glob)
  3011.     {
  3012.       if (TREE_CODE (glob) != TREE_LIST)
  3013.     {
  3014.       if (DECL_LANGUAGE (decl) == lang_c)
  3015.         {
  3016.           if (TREE_CODE (glob) == FUNCTION_DECL)
  3017.         {
  3018.           if (DECL_LANGUAGE (glob) == lang_c)
  3019.             {
  3020.               error_with_decl (decl, "C-language function `%s' overloaded here");
  3021.               error_with_decl (glob, "Previous C-language version of this function was `%s'");
  3022.             }
  3023.         }
  3024.           else
  3025.         my_friendly_abort (9);
  3026.         }
  3027.       if (forgettable
  3028.           && ! flag_traditional
  3029.           && TREE_PERMANENT (glob) == 1
  3030.           && !global_bindings_p ())
  3031.         overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget);
  3032.       /* We cache the value of builtin functions as ADDR_EXPRs
  3033.          in the name space.  Convert it to some kind of _DECL after
  3034.          remembering what to forget.  */
  3035.       if (TREE_CODE (glob) == ADDR_EXPR)
  3036.         glob = TREE_OPERAND (glob, 0);
  3037.  
  3038.       if (TREE_CODE (glob) == FUNCTION_DECL
  3039.           && DECL_LANGUAGE (glob) != DECL_LANGUAGE (decl)
  3040.           && comptypes (TREE_TYPE (glob), TREE_TYPE (decl), 1))
  3041.         {
  3042.           if (current_lang_stack == current_lang_base)
  3043.         {
  3044.           DECL_LANGUAGE (decl) = DECL_LANGUAGE (glob);
  3045.           return glob;
  3046.         }
  3047.           else
  3048.         {
  3049.           error_with_decl (decl, "conflicting language contexts for declaration of `%s';");
  3050.           error_with_decl (glob, "conflicts with previous declaration here");
  3051.         }
  3052.         }
  3053.       if (pedantic && TREE_CODE (glob) == VAR_DECL)
  3054.         {
  3055.           my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (glob)) == 'd', 143);
  3056.           error_with_decl (glob, "non-function declaration `%s'");
  3057.           error_with_decl (decl, "conflicts with function declaration `%s'");
  3058.         }
  3059.       glob = tree_cons (orig_name, glob, NULL_TREE);
  3060.       glob = tree_cons (TREE_PURPOSE (glob), decl, glob);
  3061.       IDENTIFIER_GLOBAL_VALUE (orig_name) = glob;
  3062.       TREE_TYPE (glob) = unknown_type_node;
  3063.       return decl;
  3064.     }
  3065.  
  3066.       if (TREE_VALUE (glob) == NULL_TREE)
  3067.     {
  3068.       TREE_VALUE (glob) = decl;
  3069.       return decl;
  3070.     }
  3071.       if (TREE_CODE (decl) != TEMPLATE_DECL)
  3072.         {
  3073.           tree name = DECL_ASSEMBLER_NAME (decl);
  3074.           tree tmp;
  3075.       
  3076.       for (tmp = glob; tmp; tmp = TREE_CHAIN (tmp))
  3077.         {
  3078.           if (TREE_CODE (TREE_VALUE (tmp)) == FUNCTION_DECL
  3079.           && DECL_LANGUAGE (TREE_VALUE (tmp)) != DECL_LANGUAGE (decl)
  3080.           && comptypes (TREE_TYPE (TREE_VALUE (tmp)), TREE_TYPE (decl),
  3081.                 1))
  3082.         {
  3083.           error_with_decl (decl,
  3084.                    "conflicting language contexts for declaration of `%s';");
  3085.           error_with_decl (TREE_VALUE (tmp),
  3086.                    "conflicts with previous declaration here");
  3087.         }
  3088.           if (TREE_CODE (TREE_VALUE (tmp)) != TEMPLATE_DECL
  3089.           && DECL_ASSEMBLER_NAME (TREE_VALUE (tmp)) == name)
  3090.         return decl;
  3091.         }
  3092.     }
  3093.     }
  3094.   if (DECL_LANGUAGE (decl) == lang_c)
  3095.     {
  3096.       tree decls = glob;
  3097.       while (decls && DECL_LANGUAGE (TREE_VALUE (decls)) == lang_cplusplus)
  3098.     decls = TREE_CHAIN (decls);
  3099.       if (decls)
  3100.     {
  3101.       error_with_decl (decl, "C-language function `%s' overloaded here");
  3102.       error_with_decl (TREE_VALUE (decls), "Previous C-language version of this function was `%s'");
  3103.     }
  3104.     }
  3105.  
  3106.   if (forgettable
  3107.       && ! flag_traditional
  3108.       && (glob == 0 || TREE_PERMANENT (glob) == 1)
  3109.       && !global_bindings_p ()
  3110.       && !pseudo_global_level_p ())
  3111.     overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget);
  3112.   glob = tree_cons (orig_name, decl, glob);
  3113.   IDENTIFIER_GLOBAL_VALUE (orig_name) = glob;
  3114.   TREE_TYPE (glob) = unknown_type_node;
  3115.   return decl;
  3116. }
  3117.  
  3118. /* Generate an implicit declaration for identifier FUNCTIONID
  3119.    as a function of type int ().  Print a warning if appropriate.  */
  3120.  
  3121. tree
  3122. implicitly_declare (functionid)
  3123.      tree functionid;
  3124. {
  3125.   register tree decl;
  3126.   int temp = allocation_temporary_p ();
  3127.  
  3128.   push_obstacks_nochange ();
  3129.  
  3130.   /* Save the decl permanently so we can warn if definition follows.
  3131.      In ANSI C, warn_implicit is usually false, so the saves little space.
  3132.      But in C++, it's usually true, hence the extra code.  */
  3133.   if (temp && (flag_traditional || !warn_implicit
  3134.            || current_binding_level == global_binding_level))
  3135.     end_temporary_allocation ();
  3136.  
  3137.   /* We used to reuse an old implicit decl here,
  3138.      but this loses with inline functions because it can clobber
  3139.      the saved decl chains.  */
  3140. /*  if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0)
  3141.     decl = IDENTIFIER_IMPLICIT_DECL (functionid);
  3142.   else  */
  3143.     decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
  3144.  
  3145.   DECL_EXTERNAL (decl) = 1;
  3146.   TREE_PUBLIC (decl) = 1;
  3147.  
  3148.   /* ANSI standard says implicit declarations are in the innermost block.
  3149.      So we record the decl in the standard fashion.
  3150.      If flag_traditional is set, pushdecl does it top-level.  */
  3151.   pushdecl (decl);
  3152.   rest_of_decl_compilation (decl, 0, 0, 0);
  3153.  
  3154.   if (warn_implicit
  3155.       /* Only one warning per identifier.  */
  3156.       && IDENTIFIER_IMPLICIT_DECL (functionid) == 0)
  3157.     {
  3158.       pedwarn ("implicit declaration of function `%s'",
  3159.            IDENTIFIER_POINTER (functionid));
  3160.     }
  3161.  
  3162.   SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
  3163.  
  3164.   pop_obstacks ();
  3165.  
  3166.   return decl;
  3167. }
  3168.  
  3169. /* Return zero if the declaration NEWDECL is valid
  3170.    when the declaration OLDDECL (assumed to be for the same name)
  3171.    has already been seen.
  3172.    Otherwise return an error message format string with a %s
  3173.    where the identifier should go.  */
  3174.  
  3175. static char *
  3176. redeclaration_error_message (newdecl, olddecl)
  3177.      tree newdecl, olddecl;
  3178. {
  3179.   if (TREE_CODE (newdecl) == TYPE_DECL)
  3180.     {
  3181.       /* Because C++ can put things into name space for free,
  3182.      constructs like "typedef struct foo { ... } foo"
  3183.      would look like an erroneous redeclaration.  */
  3184.       if (TREE_TYPE (olddecl) == TREE_TYPE (newdecl))
  3185.     return 0;
  3186.       else
  3187.     return "redefinition of `%s'";
  3188.     }
  3189.   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
  3190.     {
  3191.       /* If this is a pure function, its olddecl will actually be
  3192.      the original initialization to `0' (which we force to call
  3193.      abort()).  Don't complain about redefinition in this case.  */
  3194.       if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl))
  3195.     return 0;
  3196.  
  3197.       /* Declarations of functions can insist on internal linkage
  3198.      but they can't be inconsistent with internal linkage,
  3199.      so there can be no error on that account.
  3200.      However defining the same name twice is no good.  */
  3201.       if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0
  3202.       /* However, defining once as extern inline and a second
  3203.          time in another way is ok.  */
  3204.       && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl)
  3205.            && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl))))
  3206.     {
  3207.       if (DECL_NAME (olddecl) == NULL_TREE)
  3208.         return "`%s' not declared in class";
  3209.       else
  3210.         return "redefinition of `%s'";
  3211.     }
  3212.       return 0;
  3213.     }
  3214.   else if (current_binding_level == global_binding_level)
  3215.     {
  3216.       /* Objects declared at top level:  */
  3217.       /* If at least one is a reference, it's ok.  */
  3218.       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
  3219.     return 0;
  3220.       /* Reject two definitions.  */
  3221.       if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0)
  3222.     return "redefinition of `%s'";
  3223.       /* Now we have two tentative defs, or one tentative and one real def.  */
  3224.       /* Insist that the linkage match.  */
  3225.       if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
  3226.     return "conflicting declarations of `%s'";
  3227.       return 0;
  3228.     }
  3229.   else
  3230.     {
  3231.       /* Objects declared with block scope:  */
  3232.       /* Reject two definitions, and reject a definition
  3233.      together with an external reference.  */
  3234.       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
  3235.     return "redeclaration of `%s'";
  3236.       return 0;
  3237.     }
  3238. }
  3239.  
  3240. /* Get the LABEL_DECL corresponding to identifier ID as a label.
  3241.    Create one if none exists so far for the current function.
  3242.    This function is called for both label definitions and label references.  */
  3243.  
  3244. tree
  3245. lookup_label (id)
  3246.      tree id;
  3247. {
  3248.   register tree decl = IDENTIFIER_LABEL_VALUE (id);
  3249.  
  3250.   if ((decl == 0
  3251.       || DECL_SOURCE_LINE (decl) == 0)
  3252.       && (named_label_uses == 0
  3253.       || TREE_PURPOSE (named_label_uses) != current_binding_level->names
  3254.       || TREE_VALUE (named_label_uses) != decl))
  3255.     {
  3256.       named_label_uses
  3257.     = tree_cons (current_binding_level->names, decl, named_label_uses);
  3258.       TREE_TYPE (named_label_uses) = (tree)current_binding_level;
  3259.     }
  3260.  
  3261.   /* Use a label already defined or ref'd with this name.  */
  3262.   if (decl != 0)
  3263.     {
  3264.       /* But not if it is inherited and wasn't declared to be inheritable.  */
  3265.       if (DECL_CONTEXT (decl) != current_function_decl
  3266.       && ! C_DECLARED_LABEL_FLAG (decl))
  3267.     return shadow_label (id);
  3268.       return decl;
  3269.     }
  3270.  
  3271.   decl = build_decl (LABEL_DECL, id, void_type_node);
  3272.  
  3273.   /* A label not explicitly declared must be local to where it's ref'd.  */
  3274.   DECL_CONTEXT (decl) = current_function_decl;
  3275.  
  3276.   DECL_MODE (decl) = VOIDmode;
  3277.  
  3278.   /* Say where one reference is to the label,
  3279.      for the sake of the error if it is not defined.  */
  3280.   DECL_SOURCE_LINE (decl) = lineno;
  3281.   DECL_SOURCE_FILE (decl) = input_filename;
  3282.  
  3283.   SET_IDENTIFIER_LABEL_VALUE (id, decl);
  3284.  
  3285.   named_labels = tree_cons (NULL_TREE, decl, named_labels);
  3286.   TREE_VALUE (named_label_uses) = decl;
  3287.  
  3288.   return decl;
  3289. }
  3290.  
  3291. /* Make a label named NAME in the current function,
  3292.    shadowing silently any that may be inherited from containing functions
  3293.    or containing scopes.
  3294.  
  3295.    Note that valid use, if the label being shadowed
  3296.    comes from another scope in the same function,
  3297.    requires calling declare_nonlocal_label right away.  */
  3298.  
  3299. tree
  3300. shadow_label (name)
  3301.      tree name;
  3302. {
  3303.   register tree decl = IDENTIFIER_LABEL_VALUE (name);
  3304.  
  3305.   if (decl != 0)
  3306.     {
  3307.       shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
  3308.       SET_IDENTIFIER_LABEL_VALUE (name, 0);
  3309.       SET_IDENTIFIER_LABEL_VALUE (decl, 0);
  3310.     }
  3311.  
  3312.   return lookup_label (name);
  3313. }
  3314.  
  3315. /* Define a label, specifying the location in the source file.
  3316.    Return the LABEL_DECL node for the label, if the definition is valid.
  3317.    Otherwise return 0.  */
  3318.  
  3319. tree
  3320. define_label (filename, line, name)
  3321.      char *filename;
  3322.      int line;
  3323.      tree name;
  3324. {
  3325.   tree decl = lookup_label (name);
  3326.  
  3327.   /* After labels, make any new cleanups go into their
  3328.      own new (temporary) binding contour.  */
  3329.   current_binding_level->more_cleanups_ok = 0;
  3330.  
  3331.   /* If label with this name is known from an outer context, shadow it.  */
  3332.   if (decl != 0 && DECL_CONTEXT (decl) != current_function_decl)
  3333.     {
  3334.       shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
  3335.       SET_IDENTIFIER_LABEL_VALUE (name, 0);
  3336.       decl = lookup_label (name);
  3337.     }
  3338.  
  3339.   if (DECL_INITIAL (decl) != 0)
  3340.     {
  3341.       error_with_decl (decl, "duplicate label `%s'");
  3342.       return 0;
  3343.     }
  3344.   else
  3345.     {
  3346.       tree uses, prev;
  3347.  
  3348.       /* Mark label as having been defined.  */
  3349.       DECL_INITIAL (decl) = error_mark_node;
  3350.       /* Say where in the source.  */
  3351.       DECL_SOURCE_FILE (decl) = filename;
  3352.       DECL_SOURCE_LINE (decl) = line;
  3353.  
  3354.       for (prev = 0, uses = named_label_uses;
  3355.        uses;
  3356.        prev = uses, uses = TREE_CHAIN (uses))
  3357.     if (TREE_VALUE (uses) == decl)
  3358.       {
  3359.         struct binding_level *b = current_binding_level;
  3360.         while (1)
  3361.           {
  3362.         tree new_decls = b->names;
  3363.         tree old_decls = ((tree)b == TREE_TYPE (uses)
  3364.                   ? TREE_PURPOSE (uses) : NULL_TREE);
  3365.         while (new_decls != old_decls)
  3366.           {
  3367.             if (TREE_CODE (new_decls) == VAR_DECL
  3368.             /* Don't complain about crossing initialization
  3369.                of temporaries.  They can't be accessed,
  3370.                and they should be cleaned up
  3371.                by the time we get to the label.  */
  3372.             && ! TEMP_NAME_P (DECL_NAME (new_decls))
  3373.             && ((DECL_INITIAL (new_decls) != NULL_TREE
  3374.                  && DECL_INITIAL (new_decls) != error_mark_node)
  3375.                 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
  3376.               {
  3377.             if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE)
  3378.               error_with_decl (decl, "invalid jump to label `%s'");
  3379.             SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl);
  3380.             error_with_decl (new_decls, "crosses initialization of `%s'");
  3381.               }
  3382.             new_decls = TREE_CHAIN (new_decls);
  3383.           }
  3384.         if ((tree)b == TREE_TYPE (uses))
  3385.           break;
  3386.         b = b->level_chain;
  3387.           }
  3388.  
  3389.         if (prev)
  3390.           TREE_CHAIN (prev) = TREE_CHAIN (uses);
  3391.         else
  3392.           named_label_uses = TREE_CHAIN (uses);
  3393.       }
  3394.       current_function_return_value = NULL_TREE;
  3395.       return decl;
  3396.     }
  3397. }
  3398.  
  3399. /* Same, but for CASE labels.  If DECL is NULL_TREE, it's the default.  */
  3400. void
  3401. define_case_label (decl)
  3402.      tree decl;
  3403. {
  3404.   tree cleanup = last_cleanup_this_contour ();
  3405.   if (cleanup)
  3406.     {
  3407.       static int explained = 0;
  3408.       error_with_decl (TREE_PURPOSE (cleanup), "destructor needed for `%s'");
  3409.       error ("where case label appears here");
  3410.       if (!explained)
  3411.     {
  3412.       error ("(enclose actions of previous case statements requiring");
  3413.       error ("destructors in their own binding contours.)");
  3414.       explained = 1;
  3415.     }
  3416.     }
  3417.  
  3418.   /* After labels, make any new cleanups go into their
  3419.      own new (temporary) binding contour.  */
  3420.  
  3421.   current_binding_level->more_cleanups_ok = 0;
  3422.   current_function_return_value = NULL_TREE;
  3423. }
  3424.  
  3425. /* Return the list of declarations of the current level.
  3426.    Note that this list is in reverse order unless/until
  3427.    you nreverse it; and when you do nreverse it, you must
  3428.    store the result back using `storedecls' or you will lose.  */
  3429.  
  3430. tree
  3431. getdecls ()
  3432. {
  3433.   return current_binding_level->names;
  3434. }
  3435.  
  3436. /* Return the list of type-tags (for structs, etc) of the current level.  */
  3437.  
  3438. tree
  3439. gettags ()
  3440. {
  3441.   return current_binding_level->tags;
  3442. }
  3443.  
  3444. /* Store the list of declarations of the current level.
  3445.    This is done for the parameter declarations of a function being defined,
  3446.    after they are modified in the light of any missing parameters.  */
  3447.  
  3448. static void
  3449. storedecls (decls)
  3450.      tree decls;
  3451. {
  3452.   current_binding_level->names = decls;
  3453. }
  3454.  
  3455. /* Similarly, store the list of tags of the current level.  */
  3456.  
  3457. static void
  3458. storetags (tags)
  3459.      tree tags;
  3460. {
  3461.   current_binding_level->tags = tags;
  3462. }
  3463.  
  3464. /* Given NAME, an IDENTIFIER_NODE,
  3465.    return the structure (or union or enum) definition for that name.
  3466.    Searches binding levels from BINDING_LEVEL up to the global level.
  3467.    If THISLEVEL_ONLY is nonzero, searches only the specified context
  3468.    (but skips any tag-transparent contexts to find one that is
  3469.    meaningful for tags).
  3470.    FORM says which kind of type the caller wants;
  3471.    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
  3472.    If the wrong kind of type is found, and it's not a template, an error is
  3473.    reported.  */
  3474.  
  3475. static tree
  3476. lookup_tag (form, name, binding_level, thislevel_only)
  3477.      enum tree_code form;
  3478.      struct binding_level *binding_level;
  3479.      tree name;
  3480.      int thislevel_only;
  3481. {
  3482.   register struct binding_level *level;
  3483.  
  3484.   for (level = binding_level; level; level = level->level_chain)
  3485.     {
  3486.       register tree tail;
  3487.       if (ANON_AGGRNAME_P (name))
  3488.     for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  3489.       {
  3490.         /* There's no need for error checking here, because
  3491.            anon names are unique throughout the compilation.  */
  3492.         if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name)
  3493.           return TREE_VALUE (tail);
  3494.       }
  3495.       else
  3496.     for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  3497.       {
  3498.         if (TREE_PURPOSE (tail) == name)
  3499.           {
  3500.         enum tree_code code = TREE_CODE (TREE_VALUE (tail));
  3501.         /* Should tighten this up; it'll probably permit
  3502.            UNION_TYPE and a struct template, for example.  */
  3503.         if (code != form
  3504.             && !(form != ENUMERAL_TYPE
  3505.              && (code == TEMPLATE_DECL
  3506.                  || code == UNINSTANTIATED_P_TYPE)))
  3507.                
  3508.           {
  3509.             /* Definition isn't the kind we were looking for.  */
  3510.             error ("`%s' defined as wrong kind of tag",
  3511.                IDENTIFIER_POINTER (name));
  3512.           }
  3513.         return TREE_VALUE (tail);
  3514.           }
  3515.       }
  3516.       if (thislevel_only && ! level->tag_transparent)
  3517.     return NULL_TREE;
  3518.       if (current_class_type && level->level_chain == global_binding_level)
  3519.     {
  3520.       /* Try looking in this class's tags before heading into
  3521.          global binding level.  */
  3522.       tree context = current_class_type;
  3523.       while (context)
  3524.         {
  3525.           switch (TREE_CODE_CLASS (TREE_CODE (context)))
  3526.         {
  3527.         case 't':
  3528.           {
  3529.             tree these_tags = CLASSTYPE_TAGS (context);
  3530.             if (ANON_AGGRNAME_P (name))
  3531.               while (these_tags)
  3532.             {
  3533.               if (TYPE_IDENTIFIER (TREE_VALUE (these_tags))
  3534.                   == name)
  3535.                 return TREE_VALUE (tail);
  3536.               these_tags = TREE_CHAIN (these_tags);
  3537.             }
  3538.             else
  3539.               while (these_tags)
  3540.             {
  3541.               if (TREE_PURPOSE (these_tags) == name)
  3542.                 {
  3543.                   if (TREE_CODE (TREE_VALUE (these_tags)) != form)
  3544.                 {
  3545.                   error ("`%s' defined as wrong kind of tag in class scope",
  3546.                      IDENTIFIER_POINTER (name));
  3547.                 }
  3548.                   return TREE_VALUE (tail);
  3549.                 }
  3550.               these_tags = TREE_CHAIN (these_tags);
  3551.             }
  3552.             /* If this type is not yet complete, then don't
  3553.                look at its context.  */
  3554.             if (TYPE_SIZE (context) == NULL_TREE)
  3555.               goto no_context;
  3556.             /* Go to next enclosing type, if any.  */
  3557.             context = DECL_CONTEXT (TYPE_NAME (context));
  3558.             break;
  3559.           case 'd':
  3560.             context = DECL_CONTEXT (context);
  3561.             break;
  3562.           default:
  3563.             my_friendly_abort (10);
  3564.           }
  3565.           continue;
  3566.         }
  3567.         no_context:
  3568.           break;
  3569.         }
  3570.     }
  3571.     }
  3572.   return NULL_TREE;
  3573. }
  3574.  
  3575. void
  3576. set_current_level_tags_transparency (tags_transparent)
  3577.      int tags_transparent;
  3578. {
  3579.   current_binding_level->tag_transparent = tags_transparent;
  3580. }
  3581.  
  3582. /* Given a type, find the tag that was defined for it and return the tag name.
  3583.    Otherwise return 0.  However, the value can never be 0
  3584.    in the cases in which this is used.
  3585.  
  3586.    C++: If NAME is non-zero, this is the new name to install.  This is
  3587.    done when replacing anonymous tags with real tag names.  */
  3588.  
  3589. static tree
  3590. lookup_tag_reverse (type, name)
  3591.      tree type;
  3592.      tree name;
  3593. {
  3594.   register struct binding_level *level;
  3595.  
  3596.   for (level = current_binding_level; level; level = level->level_chain)
  3597.     {
  3598.       register tree tail;
  3599.       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  3600.     {
  3601.       if (TREE_VALUE (tail) == type)
  3602.         {
  3603.           if (name)
  3604.         TREE_PURPOSE (tail) = name;
  3605.           return TREE_PURPOSE (tail);
  3606.         }
  3607.     }
  3608.     }
  3609.   return NULL_TREE;
  3610. }
  3611.  
  3612. /* Given type TYPE which was not declared in C++ language context,
  3613.    attempt to find a name by which it is referred.  */
  3614. tree
  3615. typedecl_for_tag (tag)
  3616.      tree tag;
  3617. {
  3618.   struct binding_level *b = current_binding_level;
  3619.  
  3620.   if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
  3621.     return TYPE_NAME (tag);
  3622.  
  3623.   while (b)
  3624.     {
  3625.       tree decls = b->names;
  3626.       while (decls)
  3627.     {
  3628.       if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
  3629.         break;
  3630.       decls = TREE_CHAIN (decls);
  3631.     }
  3632.       if (decls)
  3633.     return decls;
  3634.       b = b->level_chain;
  3635.     }
  3636.   return NULL_TREE;
  3637. }
  3638.  
  3639. /* Called when we must retroactively globalize a type we previously
  3640.    thought needed to be nested.  This happens, for example, when
  3641.    a `friend class' declaration is seen for an undefined type.  */
  3642.  
  3643. static void
  3644. globalize_nested_type (type)
  3645.      tree type;
  3646. {
  3647.   tree t, prev = NULL_TREE, d = TYPE_NAME (type);
  3648.   struct binding_level *b;
  3649.  
  3650.   my_friendly_assert (TREE_CODE (d) == TYPE_DECL, 144);
  3651.   /* If the type value has already been globalized, then we're set.  */
  3652.   if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (d)) == d)
  3653.     return;
  3654.   if (IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (d)))
  3655.     {
  3656.       /* If this type already made it into the global tags,
  3657.      silently return.  */
  3658.       if (value_member (type, global_binding_level->tags))
  3659.     return;
  3660.     }
  3661.  
  3662.   set_identifier_type_value (DECL_NESTED_TYPENAME (d), NULL_TREE);
  3663.   DECL_NESTED_TYPENAME (d) = DECL_NAME (d);
  3664.   DECL_CONTEXT (d) = NULL_TREE;
  3665.   if (class_binding_level)
  3666.     b = class_binding_level;
  3667.   else
  3668.     b = current_binding_level;
  3669.   while (b != global_binding_level)
  3670.     {
  3671.       prev = NULL_TREE;
  3672.       if (b->parm_flag == 2)
  3673.     for (t = b->tags; t != NULL_TREE; prev = t, t = TREE_CHAIN (t))
  3674.       if (TREE_VALUE (t) == type)
  3675.         goto found;
  3676.       b = b->level_chain;
  3677.     }
  3678.   /* We failed to find this tag anywhere up the binding chains.
  3679.      B is now the global binding level... check there.  */
  3680.   prev = NULL_TREE;
  3681.   if (b->parm_flag == 2)
  3682.     for (t = b->tags; t != NULL_TREE; prev = t, t = TREE_CHAIN (t))
  3683.       if (TREE_VALUE (t) == type)
  3684.     goto foundglobal;
  3685.   /* It wasn't in global scope either, so this is an anonymous forward ref
  3686.      of some kind; let it happen.  */
  3687.   return;
  3688.  
  3689. foundglobal:
  3690.   print_node_brief (stderr, "Tried to globalize already-global type ",
  3691.             type, 0);
  3692.   my_friendly_abort (11);
  3693.  
  3694. found:
  3695.   /* Pull the tag out of the nested binding contour.  */
  3696.   if (prev)
  3697.     TREE_CHAIN (prev) = TREE_CHAIN (t);
  3698.   else
  3699.     b->tags = TREE_CHAIN (t);
  3700.   
  3701.   set_identifier_type_value (TREE_PURPOSE (t), TREE_VALUE (t));
  3702.   global_binding_level->tags
  3703.     = perm_tree_cons (TREE_PURPOSE (t), TREE_VALUE (t),
  3704.               global_binding_level->tags);
  3705.  
  3706.   /* Pull the tag out of the class's tags (if there).
  3707.      It won't show up if it appears e.g. in a parameter declaration
  3708.      or definition of a member function of this type.  */
  3709.   if (current_class_type != NULL_TREE)
  3710.     {
  3711.       for (t = CLASSTYPE_TAGS (current_class_type), prev = NULL_TREE;
  3712.        t != NULL_TREE;
  3713.        prev = t, t = TREE_CHAIN (t))
  3714.     if (TREE_VALUE (t) == type)
  3715.       break;
  3716.  
  3717.       if (t != NULL_TREE)
  3718.     {
  3719.       if (prev)
  3720.         TREE_CHAIN (prev) = TREE_CHAIN (t);
  3721.       else
  3722.         CLASSTYPE_TAGS (current_class_type) = TREE_CHAIN (t);
  3723.     }
  3724.     }
  3725.  
  3726.   pushdecl_top_level (d);
  3727. }
  3728.  
  3729. static void
  3730. maybe_globalize_type (type)
  3731.      tree type;
  3732. {
  3733.   if ((((TREE_CODE (type) == RECORD_TYPE
  3734.      || TREE_CODE (type) == UNION_TYPE)
  3735.     && ! TYPE_BEING_DEFINED (type))
  3736.        || TREE_CODE (type) == ENUMERAL_TYPE)
  3737.       && TYPE_SIZE (type) == NULL_TREE
  3738.       /* This part is gross.  We keep calling here with types that
  3739.      are instantiations of templates, when that type should is
  3740.      global, or doesn't have the type decl established yet,
  3741.      so globalizing will fail (because it won't find the type in any
  3742.      non-global scope).  So we short-circuit that path.  */
  3743.       && !(TYPE_NAME (type) != NULL_TREE
  3744.        && TYPE_IDENTIFIER (type) != NULL_TREE
  3745.        && ! IDENTIFIER_HAS_TYPE_VALUE (TYPE_IDENTIFIER (type)))
  3746.       )
  3747.     globalize_nested_type (type);
  3748. }
  3749.  
  3750. /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
  3751.    Return the type value, or NULL_TREE if not found.  */
  3752. static tree
  3753. lookup_nested_type (type, context)
  3754.      tree type;
  3755.      tree context;
  3756. {
  3757.   if (context == NULL_TREE)
  3758.     return NULL_TREE;
  3759.   while (context)
  3760.     {
  3761.       switch (TREE_CODE (context))
  3762.     {
  3763.     case TYPE_DECL:
  3764.       {
  3765.         tree ctype = TREE_TYPE (context);
  3766.         tree match = value_member (type, CLASSTYPE_TAGS (ctype));
  3767.         if (match)
  3768.           return TREE_VALUE (match);
  3769.         context = DECL_CONTEXT (context);
  3770.       }
  3771.       break;
  3772.     case FUNCTION_DECL:
  3773.       return TYPE_IDENTIFIER (type) ? lookup_name (TYPE_IDENTIFIER (type), 1) : NULL_TREE;
  3774.       break;
  3775.     default:
  3776.       my_friendly_abort (12);
  3777.     }
  3778.     }
  3779.   return NULL_TREE;
  3780. }
  3781.  
  3782. /* Look up NAME in the current binding level and its superiors in the
  3783.    namespace of variables, functions and typedefs.  Return a ..._DECL
  3784.    node of some kind representing its definition if there is only one
  3785.    such declaration, or return a TREE_LIST with all the overloaded
  3786.    definitions if there are many, or return 0 if it is undefined.
  3787.  
  3788.    If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
  3789.    If PREFER_TYPE is = 0, we prefer non-TYPE_DECLs.
  3790.    If PREFER_TYPE is < 0, we arbitrate according to lexical context.  */
  3791.  
  3792. tree
  3793. lookup_name (name, prefer_type)
  3794.      tree name;
  3795.      int prefer_type;
  3796. {
  3797.   register tree val;
  3798.  
  3799.   if (current_binding_level != global_binding_level
  3800.       && IDENTIFIER_LOCAL_VALUE (name))
  3801.     val = IDENTIFIER_LOCAL_VALUE (name);
  3802.   /* In C++ class fields are between local and global scope,
  3803.      just before the global scope.  */
  3804.   else if (current_class_type)
  3805.     {
  3806.       val = IDENTIFIER_CLASS_VALUE (name);
  3807.       if (val == NULL_TREE
  3808.       && TYPE_SIZE (current_class_type) == 0
  3809.       && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
  3810.     {
  3811.       /* Try to find values from base classes
  3812.          if we are presently defining a type.
  3813.          We are presently only interested in TYPE_DECLs.  */
  3814.       val = lookup_field (current_class_type, name, 0, prefer_type==-1);
  3815.       if (val == error_mark_node)
  3816.         return val;
  3817.       if (val && TREE_CODE (val) != TYPE_DECL)
  3818.         val = NULL_TREE;
  3819.     }
  3820.       if (val == NULL_TREE)
  3821.     val = lookup_nested_field (name);
  3822.       if (val == NULL_TREE)
  3823.     val = IDENTIFIER_GLOBAL_VALUE (name);
  3824.     }
  3825.   else
  3826.     val = IDENTIFIER_GLOBAL_VALUE (name);
  3827.  
  3828.   if (val)
  3829.     {
  3830.       extern int looking_for_typename;
  3831.  
  3832.       /* Arbitrate between finding a TYPE_DECL and finding
  3833.      other kinds of _DECLs.  */
  3834.       if (TREE_CODE (val) == TYPE_DECL || looking_for_typename < 0)
  3835.     return val;
  3836.  
  3837.       if (IDENTIFIER_HAS_TYPE_VALUE (name))
  3838.     {
  3839.       register tree val_as_type = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name));
  3840.  
  3841.       if (val == val_as_type || prefer_type > 0
  3842.           || looking_for_typename > 0)
  3843.         return val_as_type;
  3844.       if (prefer_type == 0)
  3845.         return val;
  3846.       return arbitrate_lookup (name, val, val_as_type);
  3847.     }
  3848.       if (TREE_TYPE (val) == error_mark_node)
  3849.     return error_mark_node;
  3850.     }
  3851.  
  3852.   return val;
  3853. }
  3854.  
  3855. /* Similar to `lookup_name' but look only at current binding level.  */
  3856.  
  3857. static tree
  3858. lookup_name_current_level (name)
  3859.      tree name;
  3860. {
  3861.   register tree t;
  3862.  
  3863.   if (current_binding_level == global_binding_level)
  3864.     return IDENTIFIER_GLOBAL_VALUE (name);
  3865.  
  3866.   if (IDENTIFIER_LOCAL_VALUE (name) == 0)
  3867.     return 0;
  3868.  
  3869.   for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
  3870.     if (DECL_NAME (t) == name)
  3871.       break;
  3872.  
  3873.   return t;
  3874. }
  3875.  
  3876. /* Arrange for the user to get a source line number, even when the
  3877.    compiler is going down in flames, so that she at least has a
  3878.    chance of working around problems in the compiler.  We used to
  3879.    call error(), but that let the segmentation fault continue
  3880.    through; now, it's much more passive by asking them to send the
  3881.    maintainers mail about the problem.  */
  3882.  
  3883. static void sigsegv ()
  3884. {
  3885.   signal (SIGSEGV, SIG_DFL);
  3886.   my_friendly_abort (0);
  3887. }
  3888.  
  3889. /* Array for holding types considered "built-in".  These types
  3890.    are output in the module in which `main' is defined.  */
  3891. static tree *builtin_type_tdescs_arr;
  3892. static int builtin_type_tdescs_len, builtin_type_tdescs_max;
  3893.  
  3894. /* Push the declarations of builtin types into the namespace.
  3895.    RID_INDEX, if < RID_MAX is the index of the builtin type
  3896.    in the array RID_POINTERS.  NAME is the name used when looking
  3897.    up the builtin type.  TYPE is the _TYPE node for the builtin type.  */
  3898.  
  3899. static void
  3900. record_builtin_type (rid_index, name, type)
  3901.      enum rid rid_index;
  3902.      char *name;
  3903.      tree type;
  3904. {
  3905.   tree rname = NULL_TREE, tname = NULL_TREE;
  3906.   tree tdecl;
  3907.  
  3908.   if ((int) rid_index < (int) RID_MAX)
  3909.     rname = ridpointers[(int) rid_index];
  3910.   if (name)
  3911.     tname = get_identifier (name);
  3912.  
  3913.   if (tname)
  3914.     {
  3915. #if 0 /* not yet, should get fixed properly later */
  3916.       tdecl = pushdecl (make_type_decl (tname, type));
  3917. #else
  3918.       tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
  3919. #endif
  3920.       set_identifier_type_value (tname, NULL_TREE);
  3921.       if ((int) rid_index < (int) RID_MAX)
  3922.     IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
  3923.     }
  3924.   if (rname != NULL_TREE)
  3925.     {
  3926.       if (tname != NULL_TREE)
  3927.     {
  3928.       set_identifier_type_value (rname, NULL_TREE);
  3929.       IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
  3930.     }
  3931.       else
  3932.     {
  3933. #if 0 /* not yet, should get fixed properly later */
  3934.       tdecl = pushdecl (make_type_decl (rname, type));
  3935. #else
  3936.       tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
  3937. #endif
  3938.       set_identifier_type_value (rname, NULL_TREE);
  3939.     }
  3940.     }
  3941.  
  3942.   if (flag_dossier)
  3943.     {
  3944.       if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max)
  3945.     {
  3946.       builtin_type_tdescs_max *= 2;
  3947.       builtin_type_tdescs_arr
  3948.         = (tree *)xrealloc (builtin_type_tdescs_arr,
  3949.                 builtin_type_tdescs_max * sizeof (tree));
  3950.     }
  3951.       builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
  3952.       if (TREE_CODE (type) != POINTER_TYPE)
  3953.     {
  3954.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  3955.         = build_pointer_type (type);
  3956.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  3957.         = build_type_variant (TYPE_POINTER_TO (type), 1, 0);
  3958.     }
  3959.       if (TREE_CODE (type) != VOID_TYPE)
  3960.     {
  3961.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  3962.         = build_reference_type (type);
  3963.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  3964.         = build_type_variant (TYPE_REFERENCE_TO (type), 1, 0);
  3965.     }
  3966.     }
  3967. }
  3968.  
  3969. static void
  3970. output_builtin_tdesc_entries ()
  3971. {
  3972.   extern struct obstack permanent_obstack;
  3973.  
  3974.   /* If there's more than one main in this file, don't crash.  */
  3975.   if (builtin_type_tdescs_arr == 0)
  3976.     return;
  3977.  
  3978.   push_obstacks (&permanent_obstack, &permanent_obstack);
  3979.   while (builtin_type_tdescs_len > 0)
  3980.     {
  3981.       tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len];
  3982.       tree tdesc = build_t_desc (type, 0);
  3983.       TREE_ASM_WRITTEN (tdesc) = 0;
  3984.       build_t_desc (type, 2);
  3985.     }
  3986.   free (builtin_type_tdescs_arr);
  3987.   builtin_type_tdescs_arr = 0;
  3988.   pop_obstacks ();
  3989. }
  3990.  
  3991. /* Push overloaded decl, in global scope, with one argument so it
  3992.    can be used as a callback from define_function.  */
  3993. static void
  3994. push_overloaded_decl_1 (x)
  3995.      tree x;
  3996. {
  3997.   push_overloaded_decl (x, 0);
  3998. }
  3999.  
  4000. /* Create the predefined scalar types of C,
  4001.    and some nodes representing standard constants (0, 1, (void *)0).
  4002.    Initialize the global binding level.
  4003.    Make definitions for built-in primitive functions.  */
  4004.  
  4005. void
  4006. init_decl_processing ()
  4007. {
  4008.   register tree endlink, int_endlink, double_endlink, ptr_endlink;
  4009.   tree fields[20];
  4010.   /* Either char* or void*.  */
  4011.   tree traditional_ptr_type_node;
  4012.   /* Data type of memcpy.  */
  4013.   tree memcpy_ftype;
  4014.   int wchar_type_size;
  4015.  
  4016.   /* Have to make these distinct before we try using them.  */
  4017.   lang_name_cplusplus = get_identifier ("C++");
  4018.   lang_name_c = get_identifier ("C");
  4019.  
  4020.   /* Initially, C.  */
  4021.   current_lang_name = lang_name_c;
  4022.  
  4023.   current_function_decl = NULL_TREE;
  4024.   named_labels = NULL_TREE;
  4025.   named_label_uses = NULL_TREE;
  4026.   current_binding_level = NULL_BINDING_LEVEL;
  4027.   free_binding_level = NULL_BINDING_LEVEL;
  4028.  
  4029.   /* Because most segmentation signals can be traced back into user
  4030.      code, catch them and at least give the user a chance of working
  4031.      around compiler bugs. */
  4032.   signal (SIGSEGV, sigsegv);
  4033.  
  4034.   gcc_obstack_init (&decl_obstack);
  4035.   if (flag_dossier)
  4036.     {
  4037.       builtin_type_tdescs_max = 100;
  4038.       builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
  4039.     }
  4040.  
  4041.   /* Must lay these out before anything else gets laid out.  */
  4042.   error_mark_node = make_node (ERROR_MARK);
  4043.   TREE_PERMANENT (error_mark_node) = 1;
  4044.   TREE_TYPE (error_mark_node) = error_mark_node;
  4045.   error_mark_list = build_tree_list (error_mark_node, error_mark_node);
  4046.   TREE_TYPE (error_mark_list) = error_mark_node;
  4047.  
  4048.   pushlevel (0);    /* make the binding_level structure for global names.  */
  4049.   global_binding_level = current_binding_level;
  4050.  
  4051.   this_identifier = get_identifier (THIS_NAME);
  4052.   in_charge_identifier = get_identifier (IN_CHARGE_NAME);
  4053.  
  4054.   /* Define `int' and `char' first so that dbx will output them first.  */
  4055.  
  4056.   integer_type_node = make_signed_type (INT_TYPE_SIZE);
  4057.   record_builtin_type (RID_INT, 0, integer_type_node);
  4058.  
  4059.   /* Define `char', which is like either `signed char' or `unsigned char'
  4060.      but not the same as either.  */
  4061.  
  4062.   char_type_node =
  4063.     (flag_signed_char
  4064.      ? make_signed_type (CHAR_TYPE_SIZE)
  4065.      : make_unsigned_type (CHAR_TYPE_SIZE));
  4066.   record_builtin_type (RID_CHAR, "char", char_type_node);
  4067.  
  4068.   long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
  4069.   record_builtin_type (RID_LONG, "long int", long_integer_type_node);
  4070.  
  4071.   unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
  4072.   record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
  4073.  
  4074.   long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
  4075.   record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
  4076.   record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
  4077.  
  4078.   /* `unsigned long' is the standard type for sizeof.
  4079.      Traditionally, use a signed type.
  4080.      Note that stddef.h uses `unsigned long',
  4081.      and this must agree, even of long and int are the same size.  */
  4082.   if (flag_traditional)
  4083.     sizetype = long_integer_type_node;
  4084.   else
  4085.     sizetype
  4086.       = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
  4087.  
  4088.   ptrdiff_type_node
  4089.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
  4090.  
  4091.   TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
  4092.   TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
  4093.   TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
  4094.   TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
  4095.   TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
  4096.  
  4097.   short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
  4098.   record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
  4099.  
  4100.   long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
  4101.   record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
  4102.   short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
  4103.   record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
  4104.   record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
  4105.   long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
  4106.   record_builtin_type (RID_MAX, "long long unsigned int", long_long_unsigned_type_node);
  4107.   record_builtin_type (RID_MAX, "long long unsigned", long_long_unsigned_type_node);
  4108.  
  4109.   /* Define both `signed char' and `unsigned char'.  */
  4110.   signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
  4111.   record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
  4112.   unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
  4113.   record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
  4114.  
  4115.   /* These are types that type_for_size and type_for_mode use.  */
  4116.   intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
  4117.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
  4118.   intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
  4119.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
  4120.   intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
  4121.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
  4122.   intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
  4123.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
  4124.   unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
  4125.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
  4126.   unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
  4127.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
  4128.   unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
  4129.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
  4130.   unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
  4131.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
  4132.  
  4133.   float_type_node = make_node (REAL_TYPE);
  4134.   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
  4135.   record_builtin_type (RID_FLOAT, 0, float_type_node);
  4136.   layout_type (float_type_node);
  4137.  
  4138.   double_type_node = make_node (REAL_TYPE);
  4139.   if (flag_short_double)
  4140.     TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
  4141.   else
  4142.     TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
  4143.   record_builtin_type (RID_DOUBLE, 0, double_type_node);
  4144.   layout_type (double_type_node);
  4145.  
  4146.   long_double_type_node = make_node (REAL_TYPE);
  4147.   TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
  4148.   record_builtin_type (RID_MAX, "long double", long_double_type_node);
  4149.   layout_type (long_double_type_node);
  4150.  
  4151.   integer_zero_node = build_int_2 (0, 0);
  4152.   TREE_TYPE (integer_zero_node) = integer_type_node;
  4153.   integer_one_node = build_int_2 (1, 0);
  4154.   TREE_TYPE (integer_one_node) = integer_type_node;
  4155.   integer_two_node = build_int_2 (2, 0);
  4156.   TREE_TYPE (integer_two_node) = integer_type_node;
  4157.   integer_three_node = build_int_2 (3, 0);
  4158.   TREE_TYPE (integer_three_node) = integer_type_node;
  4159.   empty_init_node = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
  4160.  
  4161.   /* These are needed by stor-layout.c.  */
  4162.   size_zero_node = size_int (0);
  4163.   size_one_node = size_int (1);
  4164.  
  4165.   void_type_node = make_node (VOID_TYPE);
  4166.   record_builtin_type (RID_VOID, 0, void_type_node);
  4167.   layout_type (void_type_node); /* Uses integer_zero_node.  */
  4168.   void_list_node = build_tree_list (NULL_TREE, void_type_node);
  4169.   TREE_PARMLIST (void_list_node) = 1;
  4170.  
  4171. #if defined(APPLE_HAX) && defined(PTR_HACK)
  4172.   null_DPpointer_node = build_int_2 (0, 0);
  4173.   TREE_TYPE (null_DPpointer_node) = copy_node(build_pointer_type (void_type_node));
  4174.   layout_type (TREE_TYPE (null_DPpointer_node));
  4175.   TYPE_MODE(TREE_TYPE (null_TPpointer_node)) = DPmode;
  4176.   null_TPpointer_node = build_int_2 (0, 0);
  4177.   TREE_TYPE (null_TPpointer_node) = copy_node(build_pointer_type (void_type_node));
  4178.   layout_type (TREE_TYPE (null_TPpointer_node));
  4179.   TYPE_MODE(TREE_TYPE (null_TPpointer_node)) = TPmode;
  4180. #else
  4181.   null_pointer_node = build_int_2 (0, 0);
  4182.   TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
  4183.   layout_type (TREE_TYPE (null_pointer_node));
  4184. #endif
  4185.  
  4186.   /* Used for expressions that do nothing, but are not errors.  */
  4187.   void_zero_node = build_int_2 (0, 0);
  4188.   TREE_TYPE (void_zero_node) = void_type_node;
  4189.  
  4190.   string_type_node = build_pointer_type (char_type_node);
  4191.   const_string_type_node = build_pointer_type (build_type_variant (char_type_node, 1, 0));
  4192.   record_builtin_type (RID_MAX, 0, string_type_node);
  4193.  
  4194.   /* make a type for arrays of 256 characters.
  4195.      256 is picked randomly because we have a type for integers from 0 to 255.
  4196.      With luck nothing will ever really depend on the length of this
  4197.      array type.  */
  4198.   char_array_type_node
  4199.     = build_array_type (char_type_node, unsigned_char_type_node);
  4200.   /* Likewise for arrays of ints.  */
  4201.   int_array_type_node
  4202.     = build_array_type (integer_type_node, unsigned_char_type_node);
  4203.  
  4204.   /* This is just some anonymous class type.  Nobody should ever
  4205.      need to look inside this envelope.  */
  4206.   class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
  4207.  
  4208.   default_function_type
  4209.     = build_function_type (integer_type_node, NULL_TREE);
  4210.   build_pointer_type (default_function_type);
  4211.  
  4212.   ptr_type_node = build_pointer_type (void_type_node);
  4213.   const_ptr_type_node = build_pointer_type (build_type_variant (void_type_node, 1, 0));
  4214.   record_builtin_type (RID_MAX, 0, ptr_type_node);
  4215.   endlink = void_list_node;
  4216.   int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
  4217.   double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
  4218.   ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
  4219.  
  4220.   double_ftype_double
  4221.     = build_function_type (double_type_node, double_endlink);
  4222.  
  4223. #ifdef APPLE_HAX
  4224.   if(flag_apple) {
  4225.     /* Initialize the "extended arg returning extended" function type. */
  4226.     extended_ftype_extended
  4227.       = build_function_type (long_double_type_node,
  4228.                  tree_cons (NULL_TREE, long_double_type_node, endlink));
  4229.   }
  4230. #endif /* APPLE_HAX */
  4231.  
  4232.   double_ftype_double_double
  4233.     = build_function_type (double_type_node,
  4234.                tree_cons (NULL_TREE, double_type_node, double_endlink));
  4235.  
  4236.   int_ftype_int
  4237.     = build_function_type (integer_type_node, int_endlink);
  4238.  
  4239.   long_ftype_long
  4240.     = build_function_type (long_integer_type_node,
  4241.                tree_cons (NULL_TREE, long_integer_type_node, endlink));
  4242.  
  4243.   void_ftype_ptr_ptr_int
  4244.     = build_function_type (void_type_node,
  4245.                tree_cons (NULL_TREE, ptr_type_node,
  4246.                       tree_cons (NULL_TREE, ptr_type_node,
  4247.                          int_endlink)));
  4248.  
  4249.   int_ftype_cptr_cptr_sizet
  4250.     = build_function_type (integer_type_node,
  4251.                tree_cons (NULL_TREE, const_ptr_type_node,
  4252.                       tree_cons (NULL_TREE, const_ptr_type_node,
  4253.                          tree_cons (NULL_TREE,
  4254.                                 sizetype,
  4255.                                 endlink))));
  4256.  
  4257.   void_ftype_ptr_int_int
  4258.     = build_function_type (void_type_node,
  4259.                tree_cons (NULL_TREE, ptr_type_node,
  4260.                       tree_cons (NULL_TREE, integer_type_node,
  4261.                          int_endlink)));
  4262.  
  4263.   string_ftype_ptr_ptr        /* strcpy prototype */
  4264.     = build_function_type (string_type_node,
  4265.                tree_cons (NULL_TREE, string_type_node,
  4266.                       tree_cons (NULL_TREE,
  4267.                          const_string_type_node,
  4268.                          endlink)));
  4269.  
  4270.   int_ftype_string_string    /* strcmp prototype */
  4271.     = build_function_type (integer_type_node,
  4272.                tree_cons (NULL_TREE, const_string_type_node,
  4273.                       tree_cons (NULL_TREE,
  4274.                          const_string_type_node,
  4275.                          endlink)));
  4276.  
  4277.   sizet_ftype_string        /* strlen prototype */
  4278.     = build_function_type (sizetype,
  4279.                tree_cons (NULL_TREE, const_string_type_node,
  4280.                       endlink));
  4281.  
  4282.   traditional_ptr_type_node
  4283.     = (flag_traditional ? string_type_node : ptr_type_node);
  4284.  
  4285.   memcpy_ftype    /* memcpy prototype */
  4286.     = build_function_type (traditional_ptr_type_node,
  4287.                tree_cons (NULL_TREE, ptr_type_node,
  4288.                       tree_cons (NULL_TREE, const_ptr_type_node,
  4289.                          tree_cons (NULL_TREE,
  4290.                                 sizetype,
  4291.                                 endlink))));
  4292.  
  4293. #ifdef VTABLE_USES_MASK
  4294.   /* This is primarily for virtual function definition.  We
  4295.      declare an array of `void *', which can later be
  4296.      converted to the appropriate function pointer type.
  4297.      To do pointers to members, we need a mask which can
  4298.      distinguish an index value into a virtual function table
  4299.      from an address.  */
  4300.   vtbl_mask = build_int_2 (~((HOST_WIDE_INT) VINDEX_MAX - 1), -1);
  4301. #endif
  4302.  
  4303.   vtbl_type_node
  4304.     = build_array_type (ptr_type_node, NULL_TREE);
  4305.   layout_type (vtbl_type_node);
  4306.   vtbl_type_node = build_type_variant (vtbl_type_node, 1, 0);
  4307.   record_builtin_type (RID_MAX, 0, vtbl_type_node);
  4308.  
  4309.   builtin_function ("__builtin_constant_p", int_ftype_int,
  4310.             BUILT_IN_CONSTANT_P, 0);
  4311.  
  4312.   builtin_function ("__builtin_alloca",
  4313.             build_function_type (ptr_type_node,
  4314.                      tree_cons (NULL_TREE,
  4315.                             sizetype,
  4316.                             endlink)),
  4317.             BUILT_IN_ALLOCA, "alloca");
  4318. #if 0
  4319.   builtin_function ("alloca",
  4320.             build_function_type (ptr_type_node,
  4321.                      tree_cons (NULL_TREE,
  4322.                             sizetype,
  4323.                             endlink)),
  4324.             BUILT_IN_ALLOCA, 0);
  4325. #endif
  4326.  
  4327.   builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, 0);
  4328.   builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS, 0);
  4329.   builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS, 0);
  4330.   builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, 0);
  4331.   builtin_function ("__builtin_fsqrt", double_ftype_double, BUILT_IN_FSQRT, 0);
  4332.   builtin_function ("__builtin_sin", double_ftype_double, BUILT_IN_SIN, 0);
  4333.   builtin_function ("__builtin_cos", double_ftype_double, BUILT_IN_COS, 0);
  4334. #if 0
  4335.   /* This does not work well with libg++.  */
  4336.   builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, 0);
  4337.   builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, 0);
  4338.   builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, 0);
  4339. #endif
  4340.   builtin_function ("__builtin_saveregs",
  4341.             build_function_type (ptr_type_node, NULL_TREE),
  4342.             BUILT_IN_SAVEREGS, 0);
  4343. #ifdef EXPAND_BUILTIN_VARARGS
  4344.   builtin_function ("__builtin_varargs",
  4345.             build_function_type (ptr_type_node,
  4346.                      tree_cons (NULL_TREE,
  4347.                             integer_type_node,
  4348.                             endlink)),
  4349.             BUILT_IN_VARARGS, 0);
  4350. #endif
  4351.   builtin_function ("__builtin_classify_type", default_function_type,
  4352.             BUILT_IN_CLASSIFY_TYPE, 0);
  4353.   builtin_function ("__builtin_next_arg",
  4354.             build_function_type (ptr_type_node, endlink),
  4355.             BUILT_IN_NEXT_ARG, 0);
  4356.  
  4357.   /* Currently under experimentation.  */
  4358.   builtin_function ("__builtin_memcpy", memcpy_ftype,
  4359.             BUILT_IN_MEMCPY, "memcpy");
  4360.   builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
  4361.             BUILT_IN_MEMCMP, "memcmp");
  4362.   builtin_function ("__builtin_strcmp", int_ftype_string_string,
  4363.             BUILT_IN_STRCMP, "strcmp");
  4364.   builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
  4365.             BUILT_IN_STRCPY, "strcpy");
  4366.   builtin_function ("__builtin_strlen", sizet_ftype_string,
  4367.             BUILT_IN_STRLEN, "strlen");
  4368.   builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, 0);
  4369.   builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, 0);
  4370.   builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, 0);
  4371.   builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, 0);
  4372.   builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, 0);
  4373. #if defined(APPLE_HAX) & defined(TARGET_ELEMS881)
  4374.   if(!TARGET_ELEMS881) {
  4375.       builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR);
  4376.       builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
  4377.       builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
  4378.   }
  4379. #endif
  4380.  
  4381. #if 0
  4382.   /* Support for these has not been written in either expand_builtin
  4383.      or build_function_call.  */
  4384.   builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0);
  4385.   builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0);
  4386.   builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, 0);
  4387.   builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0);
  4388.   builtin_function ("__builtin_fmod", double_ftype_double_double, BUILT_IN_FMOD, 0);
  4389.   builtin_function ("__builtin_frem", double_ftype_double_double, BUILT_IN_FREM, 0);
  4390.   builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET, 0);
  4391.   builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, 0);
  4392.   builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, 0);
  4393. #endif
  4394. #ifdef APPLE_HAX
  4395.   /* Hook to add extra builtin functions. */
  4396. #ifdef ADDITIONAL_BUILTINS
  4397.   ADDITIONAL_BUILTINS;
  4398. #endif
  4399. #endif /* APPLE_HAX */
  4400.  
  4401.   /* C++ extensions */
  4402.  
  4403.   unknown_type_node = make_node (UNKNOWN_TYPE);
  4404. #if 0 /* not yet, should get fixed properly later */
  4405.   pushdecl (make_type_decl (get_identifier ("unknown type"),
  4406.                unknown_type_node));
  4407. #else
  4408.   pushdecl (build_decl (TYPE_DECL,
  4409.             get_identifier ("unknown type"),
  4410.             unknown_type_node));
  4411. #endif
  4412.   TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
  4413.   TYPE_ALIGN (unknown_type_node) = 1;
  4414.   TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
  4415.   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
  4416.   TREE_TYPE (unknown_type_node) = unknown_type_node;
  4417.   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result.  */
  4418.   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
  4419.   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
  4420.  
  4421. #if 0/*def APPLE_HAX*/
  4422.   if(flag_apple) {
  4423.     /* Recognition for comp and extended type keywords. */
  4424.     pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_COMP],
  4425.               long_long_integer_type_node));
  4426.     pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_EXTENDED],
  4427.               long_double_type_node));
  4428.   }
  4429. #endif /* APPLE_HAX */
  4430.  
  4431.   /* This is special for C++ so functions can be overloaded. */
  4432.   wchar_type_node
  4433.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
  4434.   wchar_type_size = TYPE_PRECISION (wchar_type_node);
  4435.   signed_wchar_type_node = make_signed_type (wchar_type_size);
  4436.   unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
  4437.   wchar_type_node
  4438.     = TREE_UNSIGNED (wchar_type_node)
  4439.       ? unsigned_wchar_type_node
  4440.       : signed_wchar_type_node;
  4441.   record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node);
  4442.  
  4443.   /* This is for wide string constants.  */
  4444.   wchar_array_type_node
  4445.     = build_array_type (wchar_type_node, unsigned_char_type_node);
  4446.  
  4447.   /* This is a hack that should go away when we deliver the
  4448.      real gc code.  */
  4449.   if (flag_gc)
  4450.     {
  4451.       builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0);
  4452.       pushdecl (lookup_name (get_identifier ("__gc_main"), 0));
  4453.     }
  4454.  
  4455.   /* Simplify life by making a "vtable_entry_type".  Give its
  4456.      fields names so that the debugger can use them.  */
  4457.  
  4458.   vtable_entry_type = make_lang_type (RECORD_TYPE);
  4459.   fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_DELTA_NAME), short_integer_type_node);
  4460.   fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_INDEX_NAME), short_integer_type_node);
  4461.   fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_PFN_NAME), ptr_type_node);
  4462.   finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
  4463.                double_type_node);
  4464.  
  4465.   /* Make this part of an invisible union.  */
  4466.   fields[3] = copy_node (fields[2]);
  4467.   TREE_TYPE (fields[3]) = short_integer_type_node;
  4468.   DECL_NAME (fields[3]) = get_identifier (VTABLE_DELTA2_NAME);
  4469.   DECL_MODE (fields[3]) = TYPE_MODE (short_integer_type_node);
  4470.   DECL_SIZE (fields[3]) = TYPE_SIZE (short_integer_type_node);
  4471.   TREE_UNSIGNED (fields[3]) = 0;
  4472.   TREE_CHAIN (fields[2]) = fields[3];
  4473.   vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
  4474.   record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
  4475.  
  4476.   if (flag_dossier)
  4477.     {
  4478.       /* Must build __t_desc type.  Currently, type descriptors look like this:
  4479.  
  4480.      struct __t_desc
  4481.      {
  4482.            const char *name;
  4483.        int size;
  4484.        int bits;
  4485.        struct __t_desc *points_to;
  4486.        int ivars_count, meths_count;
  4487.        struct __i_desc *ivars[];
  4488.        struct __m_desc *meths[];
  4489.        struct __t_desc *parents[];
  4490.        struct __t_desc *vbases[];
  4491.        int offsets[];
  4492.      };
  4493.  
  4494.      ...as per Linton's paper.  */
  4495.  
  4496.       __t_desc_type_node = make_lang_type (RECORD_TYPE);
  4497.       __i_desc_type_node = make_lang_type (RECORD_TYPE);
  4498.       __m_desc_type_node = make_lang_type (RECORD_TYPE);
  4499.       __t_desc_array_type = build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE);
  4500.       __i_desc_array_type = build_array_type (TYPE_POINTER_TO (__i_desc_type_node), NULL_TREE);
  4501.       __m_desc_array_type = build_array_type (TYPE_POINTER_TO (__m_desc_type_node), NULL_TREE);
  4502.  
  4503.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  4504.                      string_type_node);
  4505.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
  4506.                      unsigned_type_node);
  4507.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
  4508.                      unsigned_type_node);
  4509.       fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("points_to"),
  4510.                      TYPE_POINTER_TO (__t_desc_type_node));
  4511.       fields[4] = build_lang_field_decl (FIELD_DECL,
  4512.                      get_identifier ("ivars_count"),
  4513.                      integer_type_node);
  4514.       fields[5] = build_lang_field_decl (FIELD_DECL,
  4515.                      get_identifier ("meths_count"),
  4516.                      integer_type_node);
  4517.       fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
  4518.                      build_pointer_type (__i_desc_array_type));
  4519.       fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
  4520.                      build_pointer_type (__m_desc_array_type));
  4521.       fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
  4522.                      build_pointer_type (__t_desc_array_type));
  4523.       fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
  4524.                      build_pointer_type (__t_desc_array_type));
  4525.       fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
  4526.                      build_pointer_type (integer_type_node));
  4527.       finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
  4528.  
  4529.       /* ivar descriptors look like this:
  4530.  
  4531.      struct __i_desc
  4532.      {
  4533.        const char *name;
  4534.        int offset;
  4535.        struct __t_desc *type;
  4536.      };
  4537.       */
  4538.  
  4539.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  4540.                      string_type_node);
  4541.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
  4542.                      integer_type_node);
  4543.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
  4544.                      TYPE_POINTER_TO (__t_desc_type_node));
  4545.       finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, integer_type_node);
  4546.  
  4547.       /* method descriptors look like this:
  4548.  
  4549.      struct __m_desc
  4550.      {
  4551.        const char *name;
  4552.        int vindex;
  4553.        struct __t_desc *vcontext;
  4554.        struct __t_desc *return_type;
  4555.        void (*address)();
  4556.        short parm_count;
  4557.        short required_parms;
  4558.        struct __t_desc *parm_types[];
  4559.      };
  4560.       */
  4561.  
  4562.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  4563.                      string_type_node);
  4564.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
  4565.                      integer_type_node);
  4566.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
  4567.                      TYPE_POINTER_TO (__t_desc_type_node));
  4568.       fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
  4569.                      TYPE_POINTER_TO (__t_desc_type_node));
  4570.       fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
  4571.                      build_pointer_type (default_function_type));
  4572.       fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
  4573.                      short_integer_type_node);
  4574.       fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
  4575.                      short_integer_type_node);
  4576.       fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
  4577.                      build_pointer_type (build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE)));
  4578.       finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, integer_type_node);
  4579.     }
  4580.  
  4581. #ifdef SOS
  4582.   if (flag_all_virtual == 2)
  4583.     {
  4584.       tree ptr_ftype_default
  4585.         = build_function_type (ptr_type_node, NULL_TREE);
  4586.  
  4587.       builtin_function ("sosFindCode", ptr_ftype_default, NOT_BUILT_IN, 0);
  4588.       builtin_function ("sosLookup", ptr_ftype_default, NOT_BUILT_IN, 0);
  4589.       builtin_function ("sosImport", ptr_ftype_default, NOT_BUILT_IN, 0);
  4590.       builtin_function ("sosDynError", ptr_ftype_default, NOT_BUILT_IN, 0);
  4591.  
  4592.       zlink_type = make_lang_type (RECORD_TYPE);
  4593.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("n"), string_type_node);
  4594.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("t"), char_type_node);
  4595.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("ptr"), TYPE_POINTER_TO (default_function_type));
  4596.       finish_builtin_type (zlink_type, "__zlink", fields, 2, integer_type_node);
  4597.  
  4598.       zret_type = make_lang_type (RECORD_TYPE);
  4599.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("cn"), string_type_node);
  4600.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("ptr"), build_pointer_type (TYPE_POINTER_TO (default_function_type)));
  4601.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("n"), integer_type_node);
  4602.       fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("bcl"), string_type_node);
  4603.       fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("f"), char_type_node);
  4604.       finish_builtin_type (zret_type, "__zret", fields, 4, integer_type_node);
  4605.     }
  4606. #endif
  4607.  
  4608.   /* Now, C++.  */
  4609.   current_lang_name = lang_name_cplusplus;
  4610.   if (flag_dossier)
  4611.     {
  4612.       int i = builtin_type_tdescs_len;
  4613.       while (i > 0)
  4614.     {
  4615.       tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
  4616.       TREE_ASM_WRITTEN (tdesc) = 1;
  4617.       TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
  4618.     }
  4619.     }
  4620.  
  4621.   auto_function (ansi_opname[(int) NEW_EXPR],
  4622.          build_function_type (ptr_type_node,
  4623.                       tree_cons (NULL_TREE, sizetype,
  4624.                          void_list_node)),
  4625.          NOT_BUILT_IN);
  4626.   auto_function (ansi_opname[(int) DELETE_EXPR],
  4627.          build_function_type (void_type_node,
  4628.                       tree_cons (NULL_TREE, ptr_type_node,
  4629.                          void_list_node)),
  4630.          NOT_BUILT_IN);
  4631.  
  4632.   abort_fndecl
  4633.     = define_function ("abort",
  4634.                build_function_type (void_type_node, void_list_node),
  4635.                NOT_BUILT_IN, 0, 0);
  4636.  
  4637.   unhandled_exception_fndecl
  4638.     = define_function ("__unhandled_exception",
  4639.                build_function_type (void_type_node, NULL_TREE),
  4640.                NOT_BUILT_IN, 0, 0);
  4641.  
  4642.   /* Perform other language dependent initializations.  */
  4643.   init_class_processing ();
  4644.   init_init_processing ();
  4645.   init_search_processing ();
  4646.  
  4647.   if (flag_handle_exceptions)
  4648.     {
  4649.       if (flag_handle_exceptions == 2)
  4650.     /* Too much trouble to inline all the trys needed for this.  */
  4651.     flag_this_is_variable = 2;
  4652.       init_exception_processing ();
  4653.     }
  4654.   if (flag_gc)
  4655.     init_gc_processing ();
  4656.   if (flag_no_inline)
  4657.     flag_inline_functions = 0, flag_default_inline = 0;
  4658.   if (flag_cadillac)
  4659.     init_cadillac ();
  4660.  
  4661.   /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__.  */
  4662.   declare_function_name ();
  4663.  
  4664.   /* Warnings about failure to return values are too valuable to forego.  */
  4665.   warn_return_type = 1;
  4666. }
  4667.  
  4668. /* Make a definition for a builtin function named NAME and whose data type
  4669.    is TYPE.  TYPE should be a function type with argument types.
  4670.    FUNCTION_CODE tells later passes how to compile calls to this function.
  4671.    See tree.h for its possible values.
  4672.  
  4673.    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
  4674.    the name to be called if we can't opencode the function.  */
  4675.  
  4676. tree
  4677. define_function (name, type, function_code, pfn, library_name)
  4678.      char *name;
  4679.      tree type;
  4680.      enum built_in_function function_code;
  4681.      void (*pfn)();
  4682.      char *library_name;
  4683. {
  4684.   tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
  4685.   DECL_EXTERNAL (decl) = 1;
  4686.   TREE_PUBLIC (decl) = 1;
  4687.  
  4688.   /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
  4689.      we cannot change DECL_ASSEMBLER_NAME until we have installed this
  4690.      function in the namespace.  */
  4691.   if (pfn) (*pfn) (decl);
  4692.   if (library_name)
  4693.     DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
  4694.   make_function_rtl (decl);
  4695.   if (function_code != NOT_BUILT_IN)
  4696.     {
  4697.       DECL_BUILT_IN (decl) = 1;
  4698.       DECL_SET_FUNCTION_CODE (decl, function_code);
  4699.     }
  4700.   return decl;
  4701. }
  4702.  
  4703. /* Called when a declaration is seen that contains no names to declare.
  4704.    If its type is a reference to a structure, union or enum inherited
  4705.    from a containing scope, shadow that tag name for the current scope
  4706.    with a forward reference.
  4707.    If its type defines a new named structure or union
  4708.    or defines an enum, it is valid but we need not do anything here.
  4709.    Otherwise, it is an error.
  4710.  
  4711.    C++: may have to grok the declspecs to learn about static,
  4712.    complain for anonymous unions.  */
  4713.  
  4714. void
  4715. shadow_tag (declspecs)
  4716.      tree declspecs;
  4717. {
  4718.   int found_tag = 0;
  4719.   int warned = 0;
  4720.   register tree link;
  4721.   register enum tree_code code, ok_code = ERROR_MARK;
  4722.   register tree t = NULL_TREE;
  4723.  
  4724.   for (link = declspecs; link; link = TREE_CHAIN (link))
  4725.     {
  4726.       register tree value = TREE_VALUE (link);
  4727.  
  4728.       code = TREE_CODE (value);
  4729.       if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
  4730.     /* Used to test also that TYPE_SIZE (value) != 0.
  4731.        That caused warning for `struct foo;' at top level in the file.  */
  4732.     {
  4733.       register tree name = TYPE_NAME (value);
  4734.  
  4735.       if (name == NULL_TREE)
  4736.         name = lookup_tag_reverse (value, NULL_TREE);
  4737.  
  4738.       if (name && TREE_CODE (name) == TYPE_DECL)
  4739.         name = DECL_NAME (name);
  4740.  
  4741.       if (class_binding_level)
  4742.         t = lookup_tag (code, name, class_binding_level, 1);
  4743.       else
  4744.         t = lookup_tag (code, name, current_binding_level, 1);
  4745.  
  4746.       if (t == 0)
  4747.         {
  4748.           push_obstacks (&permanent_obstack, &permanent_obstack);
  4749.           if (IS_AGGR_TYPE_CODE (code))
  4750.         t = make_lang_type (code);
  4751.           else
  4752.         t = make_node (code);
  4753.           pushtag (name, t);
  4754.           pop_obstacks ();
  4755.           ok_code = code;
  4756.           break;
  4757.         }
  4758.       else if (name != 0 || code == ENUMERAL_TYPE)
  4759.         ok_code = code;
  4760.  
  4761.       if (ok_code != ERROR_MARK)
  4762.         found_tag++;
  4763.       else
  4764.         {
  4765.           if (!warned)
  4766.         warning ("useless keyword or type name in declaration");
  4767.           warned = 1;
  4768.         }
  4769.     }
  4770.     }
  4771.  
  4772.   /* This is where the variables in an anonymous union are
  4773.      declared.  An anonymous union declaration looks like:
  4774.      union { ... } ;
  4775.      because there is no declarator after the union, the parser
  4776.      sends that declaration here.  */
  4777.   if (ok_code == UNION_TYPE
  4778.       && t != NULL_TREE
  4779.       && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
  4780.        && ANON_AGGRNAME_P (TYPE_NAME (t)))
  4781.       || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
  4782.           && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))))
  4783.     {
  4784.       /* ANSI C++ June 5 1992 WP 9.5.3.  Anonymous unions may not have
  4785.      function members.  */
  4786.       if (TYPE_FIELDS (t))
  4787.     {
  4788.       tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, NULL_TREE);
  4789.       finish_anon_union (decl);
  4790.     }
  4791.       else
  4792.     error ("anonymous union cannot have a function member");
  4793.     }
  4794.   else if (ok_code == RECORD_TYPE
  4795.        && found_tag == 1
  4796.        && TYPE_LANG_SPECIFIC (t)
  4797.        && CLASSTYPE_DECLARED_EXCEPTION (t))
  4798.     {
  4799.       if (TYPE_SIZE (t))
  4800.     error_with_aggr_type (t, "redeclaration of exception `%s'");
  4801.       else
  4802.     {
  4803.       tree ename, decl;
  4804.  
  4805.       push_obstacks (&permanent_obstack, &permanent_obstack);
  4806.  
  4807.       pushclass (t, 0);
  4808.       finish_exception (t, NULL_TREE);
  4809.  
  4810.       ename = TYPE_NAME (t);
  4811.       if (TREE_CODE (ename) == TYPE_DECL)
  4812.         ename = DECL_NAME (ename);
  4813.       decl = build_lang_field_decl (VAR_DECL, ename, t);
  4814.       finish_exception_decl (current_class_name, decl);
  4815.       end_exception_decls ();
  4816.  
  4817.       pop_obstacks ();
  4818.     }
  4819.     }
  4820.   else if (!warned && found_tag > 1)
  4821.     warning ("multiple types in one declaration");
  4822. }
  4823.  
  4824. /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
  4825.  
  4826. tree
  4827. groktypename (typename)
  4828.      tree typename;
  4829. {
  4830.   if (TREE_CODE (typename) != TREE_LIST)
  4831.     return typename;
  4832.   return grokdeclarator (TREE_VALUE (typename),
  4833.              TREE_PURPOSE (typename),
  4834.              TYPENAME, 0, NULL_TREE);
  4835. }
  4836.  
  4837. /* Decode a declarator in an ordinary declaration or data definition.
  4838.    This is called as soon as the type information and variable name
  4839.    have been parsed, before parsing the initializer if any.
  4840.    Here we create the ..._DECL node, fill in its type,
  4841.    and put it on the list of decls for the current context.
  4842.    The ..._DECL node is returned as the value.
  4843.  
  4844.    Exception: for arrays where the length is not specified,
  4845.    the type is left null, to be filled in by `finish_decl'.
  4846.  
  4847.    Function definitions do not come here; they go to start_function
  4848.    instead.  However, external and forward declarations of functions
  4849.    do go through here.  Structure field declarations are done by
  4850.    grokfield and not through here.  */
  4851.  
  4852. /* Set this to zero to debug not using the temporary obstack
  4853.    to parse initializers.  */
  4854. int debug_temp_inits = 1;
  4855.  
  4856. tree
  4857. start_decl (declarator, declspecs, initialized, raises)
  4858.      tree declspecs, declarator;
  4859.      int initialized;
  4860.      tree raises;
  4861. {
  4862.   register tree decl;
  4863.   register tree type, tem;
  4864.   tree context;
  4865.   extern int have_extern_spec;
  4866.   extern int used_extern_spec;
  4867.  
  4868.   int init_written = initialized;
  4869.  
  4870.   /* This should only be done once on the top most decl. */
  4871.   if (have_extern_spec && !used_extern_spec)
  4872.     {
  4873.       declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
  4874.       used_extern_spec = 1;
  4875.     }
  4876.  
  4877.   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises);
  4878.   if (decl == NULL_TREE || decl == void_type_node)
  4879.     return NULL_TREE;
  4880.  
  4881.   type = TREE_TYPE (decl);
  4882.  
  4883.   /* Don't lose if destructors must be executed at file-level.  */
  4884.   if (TREE_STATIC (decl)
  4885.       && TYPE_NEEDS_DESTRUCTOR (type)
  4886.       && TREE_PERMANENT (decl) == 0)
  4887.     {
  4888.       push_obstacks (&permanent_obstack, &permanent_obstack);
  4889.       decl = copy_node (decl);
  4890.       if (TREE_CODE (type) == ARRAY_TYPE)
  4891.     {
  4892.       tree itype = TYPE_DOMAIN (type);
  4893.       if (itype && ! TREE_PERMANENT (itype))
  4894.         {
  4895.           itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
  4896.           type = build_cplus_array_type (TREE_TYPE (type), itype);
  4897.           TREE_TYPE (decl) = type;
  4898.         }
  4899.     }
  4900.       pop_obstacks ();
  4901.     }
  4902.  
  4903.   /* Interesting work for this is done in `finish_exception_decl'.  */
  4904.   if (TREE_CODE (type) == RECORD_TYPE
  4905.       && CLASSTYPE_DECLARED_EXCEPTION (type))
  4906.     return decl;
  4907.  
  4908.   /* Corresponding pop_obstacks is done in `finish_decl'.  */
  4909.   push_obstacks_nochange ();
  4910.  
  4911.   context
  4912.     = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
  4913.       ? DECL_CLASS_CONTEXT (decl)
  4914.       : DECL_CONTEXT (decl);
  4915.  
  4916.   if (processing_template_decl)
  4917.     {
  4918.       tree d;
  4919.       if (TREE_CODE (decl) == FUNCTION_DECL)
  4920.         {
  4921.           /* Declarator is a call_expr; extract arguments from it, since
  4922.              grokdeclarator didn't do it.  */
  4923.           tree args;
  4924.           args = copy_to_permanent (last_function_parms);
  4925.           if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
  4926.             {
  4927.           tree t = TREE_TYPE (decl);
  4928.               tree decl;
  4929.           
  4930.               t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */
  4931.           if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE)
  4932.         {
  4933.           t = build_pointer_type (t); /* base type of `this' */
  4934. #if 1
  4935.           /* I suspect this is wrong. */
  4936.           t = build_type_variant (t, flag_this_is_variable <= 0,
  4937.                       0); /* type of `this' */
  4938. #else
  4939.           t = build_type_variant (t, 0, 0); /* type of `this' */
  4940. #endif
  4941.           t = build (PARM_DECL, t, this_identifier);
  4942.           TREE_CHAIN (t) = args;
  4943.           args = t;
  4944.         }
  4945.         }
  4946.           DECL_ARGUMENTS (decl) = args;
  4947.         }
  4948.       d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl));
  4949.       TREE_PUBLIC (d) = TREE_PUBLIC (decl) = 0;
  4950.       TREE_STATIC (d) = TREE_STATIC (decl);
  4951.       DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl)
  4952.                && !(context && !DECL_THIS_EXTERN (decl)));
  4953.       DECL_TEMPLATE_RESULT (d) = decl;
  4954.       DECL_OVERLOADED (d) = 1;
  4955.       decl = d;
  4956.     }
  4957.  
  4958.   if (context && TYPE_SIZE (context) != NULL_TREE)
  4959.     {
  4960.       /* If it was not explicitly declared `extern',
  4961.      revoke any previous claims of DECL_EXTERNAL.  */
  4962.       if (DECL_THIS_EXTERN (decl) == 0)
  4963.     DECL_EXTERNAL (decl) = 0;
  4964.       if (DECL_LANG_SPECIFIC (decl))
  4965.     DECL_IN_AGGR_P (decl) = 0;
  4966.       pushclass (context, 2);
  4967.     }
  4968.  
  4969.   /* If this type of object needs a cleanup, and control may
  4970.      jump past it, make a new binding level so that it is cleaned
  4971.      up only when it is initialized first.  */
  4972.   if (TYPE_NEEDS_DESTRUCTOR (type)
  4973.       && current_binding_level->more_cleanups_ok == 0)
  4974.     pushlevel_temporary (1);
  4975.  
  4976.   if (initialized)
  4977.     /* Is it valid for this decl to have an initializer at all?
  4978.        If not, set INITIALIZED to zero, which will indirectly
  4979.        tell `finish_decl' to ignore the initializer once it is parsed.  */
  4980.     switch (TREE_CODE (decl))
  4981.       {
  4982.       case TYPE_DECL:
  4983.     /* typedef foo = bar  means give foo the same type as bar.
  4984.        We haven't parsed bar yet, so `finish_decl' will fix that up.
  4985.        Any other case of an initialization in a TYPE_DECL is an error.  */
  4986.     if (pedantic || list_length (declspecs) > 1)
  4987.       {
  4988.         error ("typedef `%s' is initialized",
  4989.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  4990.         initialized = 0;
  4991.       }
  4992.     break;
  4993.  
  4994.       case FUNCTION_DECL:
  4995. #ifdef APPLE_HAX
  4996.         /* If Apple extensions are on, we recognize direct function definitions. */
  4997.         if (flag_apple)
  4998.       {
  4999.         /* A direct function definition looks exactly like a function
  5000.            being initialized like a variable.  We don't need to do anything
  5001.            with the initialization yet. */
  5002.         TREE_DIRECT (decl) = 1;
  5003. /*         DECL_PARAM (decl) = get_special_protocol (decl); */
  5004.         break;
  5005.       }
  5006. #endif /* APPLE_HAX */
  5007.     error ("function `%s' is initialized like a variable",
  5008.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  5009.     initialized = 0;
  5010.     break;
  5011.  
  5012.       default:
  5013.     /* Don't allow initializations for incomplete types
  5014.        except for arrays which might be completed by the initialization.  */
  5015.     if (TYPE_SIZE (type) != 0)
  5016.       ;                     /* A complete type is ok.  */
  5017.     else if (TREE_CODE (type) != ARRAY_TYPE)
  5018.       {
  5019.         error ("variable `%s' has initializer but incomplete type",
  5020.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  5021.         initialized = 0;
  5022.       }
  5023.     else if (TYPE_SIZE (TREE_TYPE (type)) == 0)
  5024.       {
  5025.         error ("elements of array `%s' have incomplete type",
  5026.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  5027.         initialized = 0;
  5028.       }
  5029.       }
  5030.  
  5031.   if (!initialized
  5032.       && TREE_CODE (decl) != TYPE_DECL
  5033.       && TREE_CODE (decl) != TEMPLATE_DECL
  5034.       && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl))
  5035.     {
  5036.       if (TYPE_SIZE (type) == 0)
  5037.     {
  5038.       error ("aggregate `%s' has incomplete type and cannot be initialized",
  5039.          IDENTIFIER_POINTER (DECL_NAME (decl)));
  5040.       /* Change the type so that assemble_variable will give
  5041.          DECL an rtl we can live with: (mem (const_int 0)).  */
  5042.       TREE_TYPE (decl) = error_mark_node;
  5043.       type = error_mark_node;
  5044.     }
  5045.       else
  5046.     {
  5047.       /* If any base type in the hierarchy of TYPE needs a constructor,
  5048.          then we set initialized to 1.  This way any nodes which are
  5049.          created for the purposes of initializing this aggregate
  5050.          will live as long as it does.  This is necessary for global
  5051.          aggregates which do not have their initializers processed until
  5052.          the end of the file.  */
  5053.       initialized = TYPE_NEEDS_CONSTRUCTING (type);
  5054.     }
  5055.     }
  5056.  
  5057.   if (initialized)
  5058.     {
  5059.       if (current_binding_level != global_binding_level
  5060.       && DECL_EXTERNAL (decl))
  5061.     warning ("declaration of `%s' has `extern' and is initialized",
  5062.          IDENTIFIER_POINTER (DECL_NAME (decl)));
  5063.       DECL_EXTERNAL (decl) = 0;
  5064.       if (current_binding_level == global_binding_level)
  5065.     TREE_STATIC (decl) = 1;
  5066.  
  5067.       /* Tell `pushdecl' this is an initialized decl
  5068.      even though we don't yet have the initializer expression.
  5069.      Also tell `finish_decl' it may store the real initializer.  */
  5070.       DECL_INITIAL (decl) = error_mark_node;
  5071.     }
  5072.  
  5073.   /* Add this decl to the current binding level, but not if it
  5074.      comes from another scope, e.g. a static member variable.
  5075.      TEM may equal DECL or it may be a previous decl of the same name.  */
  5076.   if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
  5077.       || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
  5078.       || TREE_CODE (type) == LANG_TYPE)
  5079.     tem = decl;
  5080.   else
  5081.     {
  5082.       tem = pushdecl (decl);
  5083.       if (TREE_CODE (tem) == TREE_LIST)
  5084.     {
  5085.       tree tem2 = value_member (decl, tem);
  5086.       if (tem2 != NULL_TREE)
  5087.         tem = TREE_VALUE (tem2);
  5088.       else
  5089.         {
  5090.           while (tem && ! decls_match (decl, TREE_VALUE (tem)))
  5091.         tem = TREE_CHAIN (tem);
  5092.           if (tem == NULL_TREE)
  5093.         tem = decl;
  5094.           else
  5095.         tem = TREE_VALUE (tem);
  5096.         }
  5097.     }
  5098.     }
  5099.  
  5100. #if 0
  5101.   /* We don't do this yet for GNU C++.  */
  5102.   /* For a local variable, define the RTL now.  */
  5103.   if (current_binding_level != global_binding_level
  5104.       /* But not if this is a duplicate decl
  5105.      and we preserved the rtl from the previous one
  5106.      (which may or may not happen).  */
  5107.       && DECL_RTL (tem) == 0)
  5108.     {
  5109.       if (TYPE_SIZE (TREE_TYPE (tem)) != 0)
  5110.     expand_decl (tem);
  5111.       else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
  5112.            && DECL_INITIAL (tem) != 0)
  5113.     expand_decl (tem);
  5114.     }
  5115. #endif
  5116.  
  5117.   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_OVERLOADED (decl))
  5118.     /* @@ Also done in start_function.  */
  5119.     tem = push_overloaded_decl (tem, 1);
  5120.   else if (TREE_CODE (decl) == TEMPLATE_DECL)
  5121.     {
  5122.       tree result = DECL_TEMPLATE_RESULT (decl);
  5123.       if (DECL_CONTEXT (result) != NULL_TREE)
  5124.     {
  5125.           tree type;
  5126.           type = DECL_CONTEXT (result);
  5127.           my_friendly_assert (TREE_CODE (type) == UNINSTANTIATED_P_TYPE, 145);
  5128.           if (/* TREE_CODE (result) == VAR_DECL */ 1)
  5129.             {
  5130. #if 0
  5131.               tree tmpl = UPT_TEMPLATE (type);
  5132.           
  5133.           fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__);
  5134.           print_node_brief (stderr, "", DECL_NAME (tem), 0);
  5135.           fprintf (stderr, " to class %s\n",
  5136.                IDENTIFIER_POINTER (DECL_NAME (tmpl)));
  5137.               DECL_TEMPLATE_MEMBERS (tmpl)
  5138.                 = perm_tree_cons (DECL_NAME (tem), tem,
  5139.                   DECL_TEMPLATE_MEMBERS (tmpl));
  5140. #endif
  5141.           return tem;
  5142.         }
  5143.           my_friendly_abort (13);
  5144.         }
  5145.       else if (TREE_CODE (result) == FUNCTION_DECL)
  5146.         tem = push_overloaded_decl (tem, 0);
  5147.       else if (TREE_CODE (result) == VAR_DECL
  5148.            || TREE_CODE (result) == TYPE_DECL)
  5149.     {
  5150.       sorry ("non-function templates not yet supported");
  5151.       return NULL_TREE;
  5152.     }
  5153.       else
  5154.     my_friendly_abort (14);
  5155.     }
  5156.  
  5157.   if (init_written
  5158.       && ! (TREE_CODE (tem) == PARM_DECL
  5159.         || (TREE_READONLY (tem)
  5160.         && (TREE_CODE (tem) == VAR_DECL
  5161.             || TREE_CODE (tem) == FIELD_DECL))))
  5162.     {
  5163.       /* When parsing and digesting the initializer,
  5164.      use temporary storage.  Do this even if we will ignore the value.  */
  5165.       if (current_binding_level == global_binding_level && debug_temp_inits)
  5166.     {
  5167.       if (TYPE_NEEDS_CONSTRUCTING (type) || TREE_CODE (type) == REFERENCE_TYPE)
  5168.         /* In this case, the initializer must lay down in permanent
  5169.            storage, since it will be saved until `finish_file' is run.   */
  5170.         ;
  5171.       else
  5172.         temporary_allocation ();
  5173.     }
  5174.     }
  5175.  
  5176.   if (flag_cadillac)
  5177.     cadillac_start_decl (tem);
  5178.  
  5179.   return tem;
  5180. }
  5181.  
  5182. static void
  5183. make_temporary_for_reference (decl, ctor_call, init, cleanupp)
  5184.      tree decl, ctor_call, init;
  5185.      tree *cleanupp;
  5186. {
  5187.   tree type = TREE_TYPE (decl);
  5188.   tree target_type = TREE_TYPE (type);
  5189.   tree tmp, tmp_addr;
  5190.  
  5191.   if (ctor_call)
  5192.     {
  5193.       tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1));
  5194.       if (TREE_CODE (tmp_addr) == NOP_EXPR)
  5195.     tmp_addr = TREE_OPERAND (tmp_addr, 0);
  5196.       my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146);
  5197.       tmp = TREE_OPERAND (tmp_addr, 0);
  5198.     }
  5199.   else
  5200.     {
  5201.       tmp = get_temp_name (target_type,
  5202.                current_binding_level == global_binding_level);
  5203.       tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
  5204.     }
  5205.  
  5206.   TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
  5207.   DECL_INITIAL (decl) = convert (TYPE_POINTER_TO (target_type), tmp_addr);
  5208.   TREE_TYPE (DECL_INITIAL (decl)) = type;
  5209.   if (TYPE_NEEDS_CONSTRUCTING (target_type))
  5210.     {
  5211.       if (current_binding_level == global_binding_level)
  5212.     {
  5213.       /* lay this variable out now.  Otherwise `output_addressed_constants'
  5214.          gets confused by its initializer.  */
  5215.       make_decl_rtl (tmp, 0, 1);
  5216.       static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
  5217.     }
  5218.       else
  5219.     {
  5220.       if (ctor_call != NULL_TREE)
  5221.         init = ctor_call;
  5222.       else
  5223.         init = build_method_call (tmp, constructor_name (target_type),
  5224.                       build_tree_list (NULL_TREE, init),
  5225.                       NULL_TREE, LOOKUP_NORMAL);
  5226.       DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init,
  5227.                        DECL_INITIAL (decl));
  5228.       *cleanupp = maybe_build_cleanup (tmp);
  5229.     }
  5230.     }
  5231.   else
  5232.     {
  5233.       DECL_INITIAL (tmp) = init;
  5234.       TREE_STATIC (tmp) = current_binding_level == global_binding_level;
  5235.       finish_decl (tmp, init, 0, 0);
  5236.     }
  5237.   if (TREE_STATIC (tmp))
  5238.     preserve_initializer ();
  5239. }
  5240.  
  5241. /* Handle initialization of references.
  5242.    These three arguments from from `finish_decl', and have the
  5243.    same meaning here that they do there.  */
  5244. /* quotes on semantics can be found in ARM 8.4.3. */
  5245. static void
  5246. grok_reference_init (decl, type, init, cleanupp)
  5247.      tree decl, type, init;
  5248.      tree *cleanupp;
  5249. {
  5250.   char *errstr = 0;
  5251.   int is_reference;
  5252.   tree tmp;
  5253.   tree this_ptr_type, actual_init;
  5254.  
  5255.   if (init == NULL_TREE)
  5256.     {
  5257.       if (DECL_LANG_SPECIFIC (decl) == 0 || DECL_IN_AGGR_P (decl) == 0)
  5258.     {
  5259.       error ("variable declared as reference not initialized");
  5260.       if (TREE_CODE (decl) == VAR_DECL)
  5261.         SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  5262.     }
  5263.       return;
  5264.     }
  5265.  
  5266.   if (TREE_CODE (init) == TREE_LIST)
  5267.     init = build_compound_expr (init);
  5268.   is_reference = TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE;
  5269.   tmp = is_reference ? convert_from_reference (init) : init;
  5270.  
  5271.   if (is_reference)
  5272.     {
  5273.       if (! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
  5274.                TYPE_MAIN_VARIANT (TREE_TYPE (tmp)), 0))
  5275.     errstr = "initialization of `%s' from dissimilar reference type";
  5276.       else if (TYPE_READONLY (TREE_TYPE (type))
  5277.            >= TYPE_READONLY (TREE_TYPE (TREE_TYPE (init))))
  5278.     {
  5279.       is_reference = 0;
  5280.       init = tmp;
  5281.     }
  5282.     }
  5283.   else
  5284.     {
  5285.       if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
  5286.       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
  5287.     {
  5288.       /* Note: default conversion is only called in very
  5289.          special cases.  */
  5290.       init = default_conversion (init);
  5291.     }
  5292.       if (TREE_CODE (TREE_TYPE (type)) == TREE_CODE (TREE_TYPE (init)))
  5293.     {
  5294.       if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
  5295.              TYPE_MAIN_VARIANT (TREE_TYPE (init)), 0))
  5296.         {
  5297.           /* This section implements ANSI C++ June 5 1992 WP 8.4.3.5. */
  5298.  
  5299.           /* A reference to a volatile T cannot be initialized with
  5300.          a const T, and vice-versa.  */
  5301.           if (TYPE_VOLATILE (TREE_TYPE (type)) && TREE_READONLY (init))
  5302.         errstr = "cannot initialize a reference to a volatile T with a const T";
  5303.           else if (TYPE_READONLY (TREE_TYPE (type)) && TREE_THIS_VOLATILE (init))
  5304.         errstr = "cannot initialize a reference to a const T with a volatile T";
  5305.           /* A reference to a plain T can be initialized only with
  5306.          a plain T.  */
  5307.           else if (!TYPE_VOLATILE (TREE_TYPE (type))
  5308.                && !TYPE_READONLY (TREE_TYPE (type)))
  5309.         {
  5310.           if (TREE_READONLY (init))
  5311.             errstr = "cannot initialize a reference to T with a const T";
  5312.           else if (TREE_THIS_VOLATILE (init))
  5313.             errstr = "cannot initialize a reference to T with a volatile T";
  5314.         }
  5315.         }
  5316.       else
  5317.         init = convert (TREE_TYPE (type), init);
  5318.     }
  5319.       else if (init != error_mark_node
  5320.            && ! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
  5321.                    TYPE_MAIN_VARIANT (TREE_TYPE (init)), 0))
  5322.     errstr = "invalid type conversion for reference";
  5323.     }
  5324.  
  5325.   if (errstr)
  5326.     {
  5327.       /* Things did not go smoothly; look for operator& type conversion.  */
  5328.       if (IS_AGGR_TYPE (TREE_TYPE (tmp)))
  5329.     {
  5330.       tmp = build_type_conversion (CONVERT_EXPR, type, init, 0);
  5331.       if (tmp != NULL_TREE)
  5332.         {
  5333.           init = tmp;
  5334.           if (tmp == error_mark_node)
  5335.         errstr = "ambiguous pointer conversion";
  5336.           else
  5337.         errstr = 0;
  5338.           is_reference = 1;
  5339.         }
  5340.       else
  5341.         {
  5342.           tmp = build_type_conversion (CONVERT_EXPR, TREE_TYPE (type), init, 0);
  5343.           if (tmp != NULL_TREE)
  5344.         {
  5345.           init = tmp;
  5346.           if (tmp == error_mark_node)
  5347.             errstr = "ambiguous pointer conversion";
  5348.           else
  5349.             errstr = 0;
  5350.           is_reference = 0;
  5351.         }
  5352.         }
  5353.     }
  5354.       /* Look for constructor.  */
  5355.       else if (IS_AGGR_TYPE (TREE_TYPE (type))
  5356.            && TYPE_HAS_CONSTRUCTOR (TREE_TYPE (type)))
  5357.     {
  5358.       tmp = get_temp_name (TREE_TYPE (type),
  5359.                    current_binding_level == global_binding_level);
  5360.       tmp = build_method_call (tmp, constructor_name (TREE_TYPE (type)),
  5361.                    build_tree_list (NULL_TREE, init),
  5362.                    NULL_TREE, LOOKUP_NORMAL);
  5363.       if (tmp == NULL_TREE || tmp == error_mark_node)
  5364.         {
  5365.           if (TREE_CODE (decl) == VAR_DECL)
  5366.         SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  5367.           error_with_decl (decl, "constructor failed to build reference initializer");
  5368.           return;
  5369.         }
  5370.       make_temporary_for_reference (decl, tmp, init, cleanupp);
  5371.       goto done;
  5372.     }
  5373.     }
  5374.  
  5375.   if (errstr)
  5376.     {
  5377.       error_with_decl (decl, errstr);
  5378.       if (TREE_CODE (decl) == VAR_DECL)
  5379.     SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  5380.       return;
  5381.     }
  5382.  
  5383.   /* In the case of initialization, it is permissible
  5384.      to assign one reference to another.  */
  5385.   this_ptr_type = build_pointer_type (TREE_TYPE (type));
  5386.  
  5387.   if (is_reference)
  5388.     {
  5389.       if (TREE_SIDE_EFFECTS (init))
  5390.     DECL_INITIAL (decl) = save_expr (init);
  5391.       else
  5392.     DECL_INITIAL (decl) = init;
  5393.     }
  5394.   else if (lvalue_p (init))
  5395.     {
  5396.       tmp = build_unary_op (ADDR_EXPR, init, 0);
  5397.       if (TREE_CODE (tmp) == ADDR_EXPR
  5398.       && TREE_CODE (TREE_OPERAND (tmp, 0)) == WITH_CLEANUP_EXPR)
  5399.     {
  5400.       /* Associate the cleanup with the reference so that we
  5401.          don't get burned by "aggressive" cleanup policy.  */
  5402.       *cleanupp = TREE_OPERAND (TREE_OPERAND (tmp, 0), 2);
  5403.       TREE_OPERAND (TREE_OPERAND (tmp, 0), 2) = error_mark_node;
  5404.     }
  5405.       if (IS_AGGR_TYPE (TREE_TYPE (this_ptr_type)))
  5406.     DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), tmp);
  5407.       else
  5408.     DECL_INITIAL (decl) = convert (this_ptr_type, tmp);
  5409.  
  5410.       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
  5411.       if (DECL_INITIAL (decl) == current_class_decl)
  5412.     DECL_INITIAL (decl) = copy_node (current_class_decl);
  5413.       TREE_TYPE (DECL_INITIAL (decl)) = type;
  5414.     }
  5415.   else if ((actual_init = unary_complex_lvalue (ADDR_EXPR, init)))
  5416.     {
  5417.       /* The initializer for this decl goes into its
  5418.      DECL_REFERENCE_SLOT.  Make sure that we can handle
  5419.      multiple evaluations without ill effect.  */
  5420.       if (TREE_CODE (actual_init) == ADDR_EXPR
  5421.       && TREE_CODE (TREE_OPERAND (actual_init, 0)) == TARGET_EXPR)
  5422.     actual_init = save_expr (actual_init);
  5423.       DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), actual_init);
  5424.       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
  5425.       TREE_TYPE (DECL_INITIAL (decl)) = type;
  5426.     }
  5427.   else if (TYPE_READONLY (TREE_TYPE (type)))
  5428.     /* Section 8.4.3 allows us to make a temporary for
  5429.        the initialization of const&.  */
  5430.     make_temporary_for_reference (decl, NULL_TREE, init, cleanupp);
  5431.   else
  5432.     {
  5433.       error_with_decl (decl, "type mismatch in initialization of `%s' (use `const')");
  5434.       DECL_INITIAL (decl) = error_mark_node;
  5435.     }
  5436.  
  5437.  done:
  5438.   /* ?? Can this be optimized in some cases to
  5439.      hand back the DECL_INITIAL slot??  */
  5440.   if (TYPE_SIZE (TREE_TYPE (type)))
  5441.     {
  5442.       init = convert_from_reference (decl);
  5443.       if (TREE_PERMANENT (decl))
  5444.     init = copy_to_permanent (init);
  5445.       SET_DECL_REFERENCE_SLOT (decl, init);
  5446.     }
  5447.  
  5448.   if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
  5449.     {
  5450.       expand_static_init (decl, DECL_INITIAL (decl));
  5451.       DECL_INITIAL (decl) = 0;
  5452.     }
  5453. }
  5454.  
  5455. /* Finish processing of a declaration;
  5456.    install its line number and initial value.
  5457.    If the length of an array type is not known before,
  5458.    it must be determined now, from the initial value, or it is an error.
  5459.  
  5460.    Call `pop_obstacks' iff NEED_POP is nonzero.
  5461.  
  5462.    For C++, `finish_decl' must be fairly evasive:  it must keep initializers
  5463.    for aggregates that have constructors alive on the permanent obstack,
  5464.    so that the global initializing functions can be written at the end.
  5465.  
  5466.    INIT0 holds the value of an initializer that should be allowed to escape
  5467.    the normal rules.
  5468.  
  5469.    For functions that take default parameters, DECL points to its
  5470.    "maximal" instantiation.  `finish_decl' must then also declared its
  5471.    subsequently lower and lower forms of instantiation, checking for
  5472.    ambiguity as it goes.  This can be sped up later.  */
  5473.  
  5474. void
  5475. finish_decl (decl, init, asmspec_tree, need_pop)
  5476.      tree decl, init;
  5477.      tree asmspec_tree;
  5478.      int need_pop;
  5479. {
  5480.   register tree type;
  5481.   tree cleanup = NULL_TREE, ttype;
  5482.   int was_incomplete;
  5483.   int temporary = allocation_temporary_p ();
  5484.   char *asmspec = 0;
  5485.   int was_readonly = 0;
  5486.  
  5487.   /* If this is 0, then we did not change obstacks.  */
  5488.   if (! decl)
  5489.     {
  5490.       if (init)
  5491.     error ("assignment (not initialization) in declaration");
  5492.       return;
  5493.     }
  5494.  
  5495.   if (asmspec_tree)
  5496.     {
  5497.       asmspec = TREE_STRING_POINTER (asmspec_tree);
  5498.       /* Zero out old RTL, since we will rewrite it.  */
  5499.       DECL_RTL (decl) = 0;
  5500.     }
  5501.  
  5502.   /* If the type of the thing we are declaring either has
  5503.      a constructor, or has a virtual function table pointer,
  5504.      AND its initialization was accepted by `start_decl',
  5505.      then we stayed on the permanent obstack through the
  5506.      declaration, otherwise, changed obstacks as GCC would.  */
  5507.  
  5508.   type = TREE_TYPE (decl);
  5509.  
  5510.   was_incomplete = (DECL_SIZE (decl) == 0);
  5511.  
  5512.   /* Take care of TYPE_DECLs up front.  */
  5513.   if (TREE_CODE (decl) == TYPE_DECL)
  5514.     {
  5515.       if (init && DECL_INITIAL (decl))
  5516.     {
  5517.       /* typedef foo = bar; store the type of bar as the type of foo.  */
  5518.       TREE_TYPE (decl) = type = TREE_TYPE (init);
  5519.       DECL_INITIAL (decl) = init = 0;
  5520.     }
  5521.       if (IS_AGGR_TYPE (type) && DECL_NAME (decl))
  5522.     {
  5523.       if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
  5524.         warning ("shadowing previous type declaration of `%s'",
  5525.              IDENTIFIER_POINTER (DECL_NAME (decl)));
  5526.       set_identifier_type_value (DECL_NAME (decl), type);
  5527.       CLASSTYPE_GOT_SEMICOLON (type) = 1;
  5528.     }
  5529.       GNU_xref_decl (current_function_decl, decl);
  5530.       rest_of_decl_compilation (decl, 0,
  5531.                 DECL_CONTEXT (decl) == NULL, 0);
  5532.       goto finish_end;
  5533.     }
  5534.   if (type != error_mark_node && IS_AGGR_TYPE (type)
  5535.       && CLASSTYPE_DECLARED_EXCEPTION (type))
  5536.     {
  5537.       finish_exception_decl (NULL_TREE, decl);
  5538.       CLASSTYPE_GOT_SEMICOLON (type) = 1;
  5539.       goto finish_end;
  5540.     }
  5541.   if (TREE_CODE (decl) != FUNCTION_DECL)
  5542.     {
  5543.       ttype = target_type (type);
  5544. #if 0 /* WTF?  -KR
  5545.      Leave this out until we can figure out why it was
  5546.      needed/desirable in the first place.  Then put a comment
  5547.      here explaining why.  Or just delete the code if no ill
  5548.      effects arise.  */
  5549.       if (TYPE_NAME (ttype)
  5550.       && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
  5551.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype)))
  5552.     {
  5553.       tree old_id = TYPE_IDENTIFIER (ttype);
  5554.       char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
  5555.       /* Need to preserve template data for UPT nodes.  */
  5556.       tree old_template = IDENTIFIER_TEMPLATE (old_id);
  5557.       newname[0] = '_';
  5558.       bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
  5559.          IDENTIFIER_LENGTH (old_id) + 1);
  5560.       old_id = get_identifier (newname);
  5561.       lookup_tag_reverse (ttype, old_id);
  5562.       TYPE_IDENTIFIER (ttype) = old_id;
  5563.       IDENTIFIER_TEMPLATE (old_id) = old_template;
  5564.     }
  5565. #endif
  5566.     }
  5567.  
  5568.   if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
  5569.       && TYPE_NEEDS_CONSTRUCTING (type))
  5570.     {
  5571.  
  5572.       /* Currently, GNU C++ puts constants in text space, making them
  5573.      impossible to initialize.  In the future, one would hope for
  5574.      an operating system which understood the difference between
  5575.      initialization and the running of a program.  */
  5576.       was_readonly = 1;
  5577.       TREE_READONLY (decl) = 0;
  5578.     }
  5579.  
  5580.   if (TREE_CODE (decl) == FIELD_DECL)
  5581.     {
  5582.       if (init && init != error_mark_node)
  5583.     my_friendly_assert (TREE_PERMANENT (init), 147);
  5584.  
  5585.       if (asmspec)
  5586.     {
  5587.       /* This must override the asm specifier which was placed
  5588.          by grokclassfn.  Lay this out fresh.
  5589.          
  5590.          @@ Should emit an error if this redefines an asm-specified
  5591.          @@ name, or if we have already used the function's name.  */
  5592.       DECL_RTL (TREE_TYPE (decl)) = 0;
  5593.       DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
  5594.       make_decl_rtl (decl, asmspec, 0);
  5595.     }
  5596.     }
  5597.   /* If `start_decl' didn't like having an initialization, ignore it now.  */
  5598.   else if (init != 0 && DECL_INITIAL (decl) == 0)
  5599.     init = 0;
  5600.   else if (DECL_EXTERNAL (decl))
  5601.     ;
  5602.   else if (TREE_CODE (type) == REFERENCE_TYPE)
  5603.     {
  5604.       grok_reference_init (decl, type, init, &cleanup);
  5605.       init = 0;
  5606.     }
  5607.  
  5608.   GNU_xref_decl (current_function_decl, decl);
  5609.  
  5610.   if (TREE_CODE (decl) == FIELD_DECL || DECL_EXTERNAL (decl))
  5611.     ;
  5612.   else if (TREE_CODE (decl) == CONST_DECL)
  5613.     {
  5614.       my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
  5615.  
  5616.       DECL_INITIAL (decl) = init;
  5617.  
  5618.       /* This will keep us from needing to worry about our obstacks.  */
  5619.       my_friendly_assert (init != 0, 149);
  5620.       init = 0;
  5621.     }
  5622.   else if (init)
  5623.     {
  5624.       if (TYPE_NEEDS_CONSTRUCTING (type))
  5625.     {
  5626.       if (TREE_CODE (type) == ARRAY_TYPE)
  5627.         init = digest_init (type, init, 0);
  5628.       else if (TREE_CODE (init) == CONSTRUCTOR
  5629.            && CONSTRUCTOR_ELTS (init) != NULL_TREE)
  5630.         {
  5631.           error_with_decl (decl, "`%s' must be initialized by constructor, not by `{...}'");
  5632.           init = error_mark_node;
  5633.         }
  5634. #if 0
  5635.       /* fix this in `build_functional_cast' instead.
  5636.          Here's the trigger code:
  5637.  
  5638.         struct ostream
  5639.         {
  5640.           ostream ();
  5641.           ostream (int, char *);
  5642.           ostream (char *);
  5643.           operator char *();
  5644.           ostream (void *);
  5645.           operator void *();
  5646.           operator << (int);
  5647.         };
  5648.         int buf_size = 1024;
  5649.         static char buf[buf_size];
  5650.         const char *debug(int i) {
  5651.           char *b = &buf[0];
  5652.           ostream o = ostream(buf_size, b);
  5653.           o << i;
  5654.           return buf;
  5655.         }
  5656.         */
  5657.  
  5658.       else if (TREE_CODE (init) == TARGET_EXPR
  5659.            && TREE_CODE (TREE_OPERAND (init, 1) == NEW_EXPR))
  5660.         {
  5661.           /* User wrote something like `foo x = foo (args)'  */
  5662.           my_friendly_assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL, 150);
  5663.           my_friendly_assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE, 151);
  5664.  
  5665.           /* User wrote exactly `foo x = foo (args)'  */
  5666.           if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init))
  5667.         {
  5668.           init = build (CALL_EXPR, TREE_TYPE (init),
  5669.                 TREE_OPERAND (TREE_OPERAND (init, 1), 0),
  5670.                 TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0);
  5671.           TREE_SIDE_EFFECTS (init) = 1;
  5672.         }
  5673.         }
  5674. #endif
  5675.  
  5676.       /* We must hide the initializer so that expand_decl
  5677.          won't try to do something it does not understand.  */
  5678.       if (current_binding_level == global_binding_level)
  5679.         {
  5680.           tree value = digest_init (type, empty_init_node, 0);
  5681.           DECL_INITIAL (decl) = value;
  5682.         }
  5683.       else
  5684.         DECL_INITIAL (decl) = error_mark_node;
  5685.     }
  5686.       else
  5687.     {
  5688.       if (TREE_CODE (init) != TREE_VEC)
  5689.         init = store_init_value (decl, init);
  5690.  
  5691.       if (init)
  5692.         /* Don't let anyone try to initialize this variable
  5693.            until we are ready to do so.  */
  5694.         DECL_INITIAL (decl) = error_mark_node;
  5695.     }
  5696.     }
  5697.   else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
  5698.        && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
  5699.     {
  5700.       tree ctype = type;
  5701.       while (TREE_CODE (ctype) == ARRAY_TYPE)
  5702.     ctype = TREE_TYPE (ctype);
  5703.       if (! TYPE_NEEDS_CONSTRUCTOR (ctype))
  5704.     {
  5705.       if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
  5706.         error_with_decl (decl, "structure `%s' with uninitialized const members");
  5707.       if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
  5708.         error_with_decl (decl, "structure `%s' with uninitialized reference members");
  5709.     }
  5710.  
  5711.       if (TREE_CODE (decl) == VAR_DECL
  5712.       && !TYPE_NEEDS_CONSTRUCTING (type)
  5713.       && (TYPE_READONLY (type) || TREE_READONLY (decl)))
  5714.     error_with_decl (decl, "uninitialized const `%s'");
  5715.  
  5716.       /* Initialize variables in need of static initialization
  5717.      with `empty_init_node' to keep assemble_variable from putting them
  5718.      in the wrong program space.  (Common storage is okay for non-public
  5719.      uninitialized data; the linker can't match it with storage from other
  5720.      files, and we may save some disk space.)  */
  5721.       if (flag_pic == 0
  5722.       && TREE_STATIC (decl)
  5723.       && TREE_PUBLIC (decl)
  5724.       && ! DECL_EXTERNAL (decl)
  5725.       && TREE_CODE (decl) == VAR_DECL
  5726.       && TYPE_NEEDS_CONSTRUCTING (type)
  5727.       && (DECL_INITIAL (decl) == 0
  5728.           || DECL_INITIAL (decl) == error_mark_node))
  5729.     {
  5730.       tree value = digest_init (type, empty_init_node, 0);
  5731.       DECL_INITIAL (decl) = value;
  5732.     }
  5733.     }
  5734.   else if (TREE_CODE (decl) == VAR_DECL
  5735.        && TREE_CODE (type) != REFERENCE_TYPE
  5736. #if 0
  5737.        /* const int a; should get this error. (mrs) */
  5738.        && TREE_CODE_CLASS (TREE_CODE (type)) == 't'
  5739. #endif
  5740.        && (TYPE_READONLY (type) || TREE_READONLY (decl)))
  5741.     {
  5742.       /* ``Unless explicitly declared extern, a const object does not have
  5743.      external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6 */
  5744. #if 0
  5745.       /* What is this for? (mrs) */
  5746.       if (! TREE_STATIC (decl))
  5747. #endif
  5748.     {
  5749.       error_with_decl (decl, "uninitialized const `%s'");
  5750.     }
  5751.     }
  5752.  
  5753.   /* For top-level declaration, the initial value was read in
  5754.      the temporary obstack.  MAXINDEX, rtl, etc. to be made below
  5755.      must go in the permanent obstack; but don't discard the
  5756.      temporary data yet.  */
  5757.  
  5758.   if (current_binding_level == global_binding_level && temporary)
  5759.     end_temporary_allocation ();
  5760.  
  5761.   /* Deduce size of array from initialization, if not already known.  */
  5762.  
  5763.   if (TREE_CODE (type) == ARRAY_TYPE
  5764.       && TYPE_DOMAIN (type) == 0
  5765.       && TREE_CODE (decl) != TYPE_DECL)
  5766.     {
  5767.       int do_default
  5768.     = (TREE_STATIC (decl)
  5769.        /* Even if pedantic, an external linkage array
  5770.           may have incomplete type at first.  */
  5771.        ? pedantic && DECL_EXTERNAL (decl)
  5772.        : !DECL_EXTERNAL (decl));
  5773.       tree initializer = init ? init : DECL_INITIAL (decl);
  5774.       int failure = complete_array_type (type, initializer, do_default);
  5775.  
  5776.       if (failure == 1)
  5777.     error_with_decl (decl, "initializer fails to determine size of `%s'");
  5778.  
  5779.       if (failure == 2)
  5780.     {
  5781.       if (do_default)
  5782.         error_with_decl (decl, "array size missing in `%s'");
  5783.       else if (!pedantic && TREE_STATIC (decl))
  5784.         DECL_EXTERNAL (decl) = 1;
  5785.     }
  5786.  
  5787.       if (pedantic && TYPE_DOMAIN (type) != 0
  5788.       && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
  5789.                   integer_zero_node))
  5790.     error_with_decl (decl, "zero-size array `%s'");
  5791.  
  5792.       layout_decl (decl, 0);
  5793.     }
  5794.  
  5795.   if (TREE_CODE (decl) == VAR_DECL)
  5796.     {
  5797.       if (TREE_STATIC (decl) && DECL_SIZE (decl) == 0)
  5798.     {
  5799.       /* A static variable with an incomplete type:
  5800.          that is an error if it is initialized or `static'.
  5801.          Otherwise, let it through, but if it is not `extern'
  5802.          then it may cause an error message later.  */
  5803.       if (!DECL_EXTERNAL (decl) || DECL_INITIAL (decl) != 0)
  5804.         error_with_decl (decl, "storage size of `%s' isn't known");
  5805.       init = 0;
  5806.     }
  5807.       else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == 0)
  5808.     {
  5809.       /* An automatic variable with an incomplete type:
  5810.          that is an error.  */
  5811.       error_with_decl (decl, "storage size of `%s' isn't known");
  5812.       TREE_TYPE (decl) = error_mark_node;
  5813.     }
  5814.       else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
  5815.     /* Let debugger know it should output info for this type.  */
  5816.     note_debug_info_needed (ttype);
  5817.  
  5818.       if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
  5819.       && DECL_SIZE (decl) != 0 && ! TREE_CONSTANT (DECL_SIZE (decl)))
  5820.     error_with_decl (decl, "storage size of `%s' isn't constant");
  5821.  
  5822.       if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
  5823.     {
  5824.       int yes = suspend_momentary ();
  5825.  
  5826.       /* If INIT comes from a functional cast, use the cleanup
  5827.          we built for that.  Otherwise, make our own cleanup.  */
  5828.       if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR
  5829.           && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1))
  5830.         {
  5831.           cleanup = TREE_OPERAND (init, 2);
  5832.           init = TREE_OPERAND (init, 0);
  5833.           current_binding_level->have_cleanups = 1;
  5834.           current_binding_level->more_exceptions_ok = 0;
  5835.         }
  5836.       else
  5837.         cleanup = maybe_build_cleanup (decl);
  5838.       resume_momentary (yes);
  5839.     }
  5840.     }
  5841.   /* PARM_DECLs get cleanups, too.  */
  5842.   else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
  5843.     {
  5844.       if (temporary)
  5845.     end_temporary_allocation ();
  5846.       cleanup = maybe_build_cleanup (decl);
  5847.       if (temporary)
  5848.     resume_temporary_allocation ();
  5849.     }
  5850.  
  5851.   /* Output the assembler code and/or RTL code for variables and functions,
  5852.      unless the type is an undefined structure or union.
  5853.      If not, it will get done when the type is completed.  */
  5854.  
  5855.   if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
  5856.       || TREE_CODE (decl) == RESULT_DECL)
  5857.     {
  5858.       int toplev = current_binding_level == global_binding_level;
  5859.       int was_temp
  5860.     = ((flag_traditional
  5861.         || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
  5862.        && allocation_temporary_p ());
  5863.  
  5864.       if (was_temp)
  5865.     end_temporary_allocation ();
  5866.  
  5867.       /* If we are in need of a cleanup, get out of any implicit
  5868.      handlers that have been established so far.  */
  5869.       if (cleanup && current_binding_level->parm_flag == 3)
  5870.     {
  5871.       pop_implicit_try_blocks (decl);
  5872.       current_binding_level->more_exceptions_ok = 0;
  5873.     }
  5874.  
  5875.       if (TREE_CODE (decl) == VAR_DECL
  5876.       && current_binding_level != global_binding_level
  5877.       && ! TREE_STATIC (decl)
  5878.       && type_needs_gc_entry (type))
  5879.     DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
  5880.  
  5881.       if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
  5882.     make_decl_rtl (decl, 0, toplev);
  5883.       else if (TREE_CODE (decl) == VAR_DECL
  5884.            && TREE_READONLY (decl)
  5885.            && DECL_INITIAL (decl) != 0
  5886.            && DECL_INITIAL (decl) != error_mark_node
  5887.            && DECL_INITIAL (decl) != empty_init_node)
  5888.     {
  5889.       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
  5890.  
  5891.       if (asmspec)
  5892.         DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
  5893.  
  5894.       if (! toplev
  5895.           && TREE_STATIC (decl)
  5896.           && ! TREE_SIDE_EFFECTS (decl)
  5897.           && ! TREE_PUBLIC (decl)
  5898.           && ! DECL_EXTERNAL (decl)
  5899.           && ! TYPE_NEEDS_DESTRUCTOR (type)
  5900.           && DECL_MODE (decl) != BLKmode)
  5901.         {
  5902.           /* If this variable is really a constant, then fill its DECL_RTL
  5903.          slot with something which won't take up storage.
  5904.          If something later should take its address, we can always give
  5905.          it legitimate RTL at that time.  */
  5906.           DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
  5907.           store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
  5908.           TREE_ASM_WRITTEN (decl) = 1;
  5909.         }
  5910.       else if (toplev)
  5911.         {
  5912.           /* Keep GCC from complaining that this variable
  5913.          is defined but never used.  */
  5914.           TREE_USED (decl) = 1;
  5915.           /* If this is a static const, change its apparent linkage
  5916.          if it belongs to a #pragma interface.  */
  5917.           if (TREE_STATIC (decl) && !interface_unknown)
  5918.         {
  5919.           TREE_PUBLIC (decl) = 1;
  5920.           DECL_EXTERNAL (decl) = interface_only;
  5921.         }
  5922.           make_decl_rtl (decl, asmspec, toplev);
  5923.         }
  5924.       else
  5925.         rest_of_decl_compilation (decl, asmspec, toplev, 0);
  5926.     }
  5927.       else if (TREE_CODE (decl) == VAR_DECL
  5928.            && DECL_LANG_SPECIFIC (decl)
  5929.            && DECL_IN_AGGR_P (decl))
  5930.     {
  5931.       if (TREE_STATIC (decl))
  5932.         if (init == 0
  5933. #ifdef DEFAULT_STATIC_DEFS
  5934.         /* If this code is dead, then users must
  5935.            explicitly declare static member variables
  5936.            outside the class def'n as well.  */
  5937.         && TYPE_NEEDS_CONSTRUCTING (type)
  5938. #endif
  5939.         )
  5940.           {
  5941.         DECL_EXTERNAL (decl) = 1;
  5942.         make_decl_rtl (decl, asmspec, 1);
  5943.           }
  5944.         else
  5945.           rest_of_decl_compilation (decl, asmspec, toplev, 0);
  5946.       else
  5947.         /* Just a constant field.  Should not need any rtl.  */
  5948.         goto finish_end0;
  5949.     }
  5950.       else
  5951.     rest_of_decl_compilation (decl, asmspec, toplev, 0);
  5952.  
  5953.       if (was_temp)
  5954.     resume_temporary_allocation ();
  5955.  
  5956.       if (type != error_mark_node
  5957.       && TYPE_LANG_SPECIFIC (type)
  5958.       && CLASSTYPE_ABSTRACT_VIRTUALS (type))
  5959.     abstract_virtuals_error (decl, type);
  5960.       else if ((TREE_CODE (type) == FUNCTION_TYPE
  5961.         || TREE_CODE (type) == METHOD_TYPE)
  5962.            && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
  5963.            && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
  5964.     abstract_virtuals_error (decl, TREE_TYPE (type));
  5965.  
  5966.       if (TREE_CODE (decl) == FUNCTION_DECL)
  5967.     {
  5968.       /* C++: Handle overloaded functions with default parameters.  */
  5969.       if (DECL_OVERLOADED (decl))
  5970.         {
  5971.           tree parmtypes = TYPE_ARG_TYPES (type);
  5972.           tree prev = NULL_TREE;
  5973.           tree original_name = DECL_NAME (decl);
  5974.           struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl);
  5975.           /* All variants will share an uncollectible lang_decl.  */
  5976.           copy_decl_lang_specific (decl);
  5977.  
  5978.           while (parmtypes && parmtypes != void_list_node)
  5979.         {
  5980.           if (TREE_PURPOSE (parmtypes))
  5981.             {
  5982.               tree fnname, fndecl;
  5983.               tree *argp = prev
  5984.             ? & TREE_CHAIN (prev)
  5985.               : & TYPE_ARG_TYPES (type);
  5986.  
  5987.               *argp = NULL_TREE;
  5988.               fnname = build_decl_overload (original_name, TYPE_ARG_TYPES (type), 0);
  5989.               *argp = parmtypes;
  5990.               fndecl = build_decl (FUNCTION_DECL, fnname, type);
  5991.               DECL_EXTERNAL (fndecl) = DECL_EXTERNAL (decl);
  5992.               TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl);
  5993.               DECL_INLINE (fndecl) = DECL_INLINE (decl);
  5994.               /* Keep G++ from thinking this function is unused.
  5995.              It is only used to speed up search in name space.  */
  5996.               TREE_USED (fndecl) = 1;
  5997.               TREE_ASM_WRITTEN (fndecl) = 1;
  5998.               DECL_INITIAL (fndecl) = NULL_TREE;
  5999.               DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl);
  6000.               fndecl = pushdecl (fndecl);
  6001.               DECL_INITIAL (fndecl) = error_mark_node;
  6002.               DECL_RTL (fndecl) = DECL_RTL (decl);
  6003.             }
  6004.           prev = parmtypes;
  6005.           parmtypes = TREE_CHAIN (parmtypes);
  6006.         }
  6007.           DECL_LANG_SPECIFIC (decl) = tmp_lang_decl;
  6008.         }
  6009.     }
  6010.       else if (DECL_EXTERNAL (decl))
  6011.     ;
  6012.       else if (TREE_STATIC (decl) && type != error_mark_node)
  6013.     {
  6014.       /* Cleanups for static variables are handled by `finish_file'.  */
  6015.       if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE)
  6016.         expand_static_init (decl, init);
  6017.       else if (TYPE_NEEDS_DESTRUCTOR (type))
  6018.         static_aggregates = perm_tree_cons (NULL_TREE, decl,
  6019.                         static_aggregates);
  6020.  
  6021.       /* Make entry in appropriate vector.  */
  6022.       if (flag_gc && type_needs_gc_entry (type))
  6023.         build_static_gc_entry (decl, type);
  6024.     }
  6025.       else if (current_binding_level != global_binding_level)
  6026.     {
  6027.       /* This is a declared decl which must live until the
  6028.          end of the binding contour.  It may need a cleanup.  */
  6029.  
  6030.       /* Recompute the RTL of a local array now
  6031.          if it used to be an incomplete type.  */
  6032.       if (was_incomplete && ! TREE_STATIC (decl))
  6033.         {
  6034.           /* If we used it already as memory, it must stay in memory.  */
  6035.           TREE_ADDRESSABLE (decl) = TREE_USED (decl);
  6036.           /* If it's still incomplete now, no init will save it.  */
  6037.           if (DECL_SIZE (decl) == 0)
  6038.         DECL_INITIAL (decl) = 0;
  6039.           expand_decl (decl);
  6040.         }
  6041.       else if (! TREE_ASM_WRITTEN (decl)
  6042.            && (TYPE_SIZE (type) != 0 || TREE_CODE (type) == ARRAY_TYPE))
  6043.         {
  6044.           /* Do this here, because we did not expand this decl's
  6045.          rtl in start_decl.  */
  6046.           if (DECL_RTL (decl) == 0)
  6047.         expand_decl (decl);
  6048.           else if (cleanup)
  6049.         {
  6050.           expand_decl_cleanup (NULL_TREE, cleanup);
  6051.           /* Cleanup used up here.  */
  6052.           cleanup = 0;
  6053.         }
  6054.         }
  6055.  
  6056.       if (DECL_SIZE (decl) && type != error_mark_node)
  6057.         {
  6058.           /* Compute and store the initial value.  */
  6059.           expand_decl_init (decl);
  6060.  
  6061.           if (init || TYPE_NEEDS_CONSTRUCTING (type))
  6062.         {
  6063.           emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
  6064.           expand_aggr_init (decl, init, 0);
  6065.         }
  6066.  
  6067.           /* Set this to 0 so we can tell whether an aggregate
  6068.          which was initialized was ever used.  */
  6069.           if (TYPE_NEEDS_CONSTRUCTING (type))
  6070.         TREE_USED (decl) = 0;
  6071.  
  6072.           /* Store the cleanup, if there was one.  */
  6073.           if (cleanup)
  6074.         {
  6075.           if (! expand_decl_cleanup (decl, cleanup))
  6076.             error_with_decl (decl, "parser lost in parsing declaration of `%s'");
  6077.         }
  6078.         }
  6079.     }
  6080.     finish_end0:
  6081.  
  6082.       /* Undo call to `pushclass' that was done in `start_decl'
  6083.      due to initialization of qualified member variable.
  6084.      I.e., Foo::x = 10;  */
  6085.       {
  6086.     tree context = DECL_CONTEXT (decl);
  6087.     if (context
  6088.         && TREE_CODE_CLASS (TREE_CODE (context)) == 't'
  6089.         && (TREE_CODE (decl) == VAR_DECL
  6090.         /* We also have a pushclass done that we need to undo here
  6091.            if we're at top level and declare a method.  */
  6092.         || (TREE_CODE (decl) == FUNCTION_DECL
  6093.             /* If size hasn't been set, we're still defining it,
  6094.                and therefore inside the class body; don't pop
  6095.                the binding level..  */
  6096.             && TYPE_SIZE (context) != 0
  6097.             /* The binding level gets popped elsewhere for a
  6098.                friend declaration inside another class.  */
  6099.             && TYPE_IDENTIFIER (context) == current_class_name
  6100.             )))
  6101.       popclass (1);
  6102.       }
  6103.     }
  6104.  
  6105.  finish_end:
  6106.  
  6107.   if (need_pop)
  6108.     {
  6109.       /* Resume permanent allocation, if not within a function.  */
  6110.       /* The corresponding push_obstacks_nochange is in start_decl,
  6111.      start_method, groktypename, and in grokfield.  */
  6112.       pop_obstacks ();
  6113.     }
  6114.  
  6115.   if (was_readonly)
  6116.     TREE_READONLY (decl) = 1;
  6117.  
  6118.   if (flag_cadillac)
  6119.     cadillac_finish_decl (decl);
  6120. #ifdef MPW_ASM
  6121.   if (current_binding_level == global_binding_level && !DECL_IGNORED_P(decl) && flag_apple) {
  6122.     finish_module (IDENTIFIER_POINTER (DECL_NAME (decl)));
  6123.   }
  6124. #endif
  6125. }
  6126.  
  6127. #ifdef MPW
  6128. #pragma segment CPDECL02
  6129. #endif
  6130.  
  6131. static void
  6132. expand_static_init (decl, init)
  6133.      tree decl;
  6134.      tree init;
  6135. {
  6136.   tree oldstatic = value_member (decl, static_aggregates);
  6137.   if (oldstatic)
  6138.     {
  6139.       if (TREE_PURPOSE (oldstatic))
  6140.     error_with_decl (decl, "multiple initializations given for `%s'");
  6141.     }
  6142.   else if (current_binding_level != global_binding_level)
  6143.     {
  6144.       /* Emit code to perform this initialization but once.  */
  6145.       tree temp;
  6146.  
  6147.       /* Remember this information until end of file. */
  6148.       push_obstacks (&permanent_obstack, &permanent_obstack);
  6149.  
  6150.       /* Emit code to perform this initialization but once.  */
  6151.       temp = get_temp_name (integer_type_node, 1);
  6152.       rest_of_decl_compilation (temp, NULL_TREE, 0, 0);
  6153.       expand_start_cond (build_binary_op (EQ_EXPR, temp,
  6154.                       integer_zero_node), 0);
  6155.       expand_assignment (temp, integer_one_node, 0, 0);
  6156.       if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
  6157.     {
  6158.       expand_aggr_init (decl, init, 0);
  6159.       do_pending_stack_adjust ();
  6160.     }
  6161.       else
  6162.     expand_assignment (decl, init, 0, 0);
  6163.       expand_end_cond ();
  6164.       if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
  6165.     {
  6166.       static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
  6167.       TREE_STATIC (static_aggregates) = 1;
  6168.     }
  6169.  
  6170.       /* Resume old (possibly temporary) allocation. */
  6171.       pop_obstacks ();
  6172.     }
  6173.   else
  6174.     {
  6175.       /* This code takes into account memory allocation
  6176.      policy of `start_decl'.  Namely, if TYPE_NEEDS_CONSTRUCTING
  6177.      does not hold for this object, then we must make permanent
  6178.      the storage currently in the temporary obstack.  */
  6179.       if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
  6180.     preserve_initializer ();
  6181.       static_aggregates = perm_tree_cons (init, decl, static_aggregates);
  6182.     }
  6183. }
  6184.  
  6185. /* Make TYPE a complete type based on INITIAL_VALUE.
  6186.    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
  6187.    2 if there was no information (in which case assume 1 if DO_DEFAULT).  */
  6188.  
  6189. int
  6190. complete_array_type (type, initial_value, do_default)
  6191.      tree type;
  6192.      tree initial_value;
  6193.      int do_default;
  6194. {
  6195.   register tree maxindex = NULL_TREE;
  6196.   int value = 0;
  6197.  
  6198.   if (initial_value)
  6199.     {
  6200.       /* Note MAXINDEX  is really the maximum index,
  6201.      one less than the size.  */
  6202.       if (TREE_CODE (initial_value) == STRING_CST)
  6203.     maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0);
  6204.       else if (TREE_CODE (initial_value) == CONSTRUCTOR)
  6205.     {
  6206.       register int nelts
  6207.         = list_length (CONSTRUCTOR_ELTS (initial_value));
  6208.       maxindex = build_int_2 (nelts - 1, 0);
  6209.     }
  6210.       else
  6211.     {
  6212.       /* Make an error message unless that happened already.  */
  6213.       if (initial_value != error_mark_node)
  6214.         value = 1;
  6215.  
  6216.       /* Prevent further error messages.  */
  6217.       maxindex = build_int_2 (1, 0);
  6218.     }
  6219.     }
  6220.  
  6221.   if (!maxindex)
  6222.     {
  6223.       if (do_default)
  6224.     maxindex = build_int_2 (1, 0);
  6225.       value = 2;
  6226.     }
  6227.  
  6228.   if (maxindex)
  6229.     {
  6230.       TYPE_DOMAIN (type) = build_index_type (maxindex);
  6231.       if (!TREE_TYPE (maxindex))
  6232.     TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
  6233.     }
  6234.  
  6235.   /* Lay out the type now that we can get the real answer.  */
  6236.  
  6237.   layout_type (type);
  6238.  
  6239.   return value;
  6240. }
  6241.  
  6242. /* Return zero if something is declared to be a member of type
  6243.    CTYPE when in the context of CUR_TYPE.  STRING is the error
  6244.    message to print in that case.  Otherwise, quietly return 1.  */
  6245. static int
  6246. member_function_or_else (ctype, cur_type, string)
  6247.      tree ctype, cur_type;
  6248.      char *string;
  6249. {
  6250.   if (ctype && ctype != cur_type)
  6251.     {
  6252.       error (string, TYPE_NAME_STRING (ctype));
  6253.       return 0;
  6254.     }
  6255.   return 1;
  6256. }
  6257.  
  6258. /* Subroutine of `grokdeclarator'.  */
  6259.  
  6260. /* CTYPE is class type, or null if non-class.
  6261.    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
  6262.    or METHOD_TYPE.
  6263.    DECLARATOR is the function's name.
  6264.    VIRTUALP is truthvalue of whether the function is virtual or not.
  6265.    FLAGS are to be passed through to `grokclassfn'.
  6266.    QUALS are qualifiers indicating whether the function is `const'
  6267.    or `volatile'.
  6268.    RAISES is a list of exceptions that this function can raise.
  6269.    CHECK is 1 if we must find this method in CTYPE, 0 if we should
  6270.    not look, and -1 if we should not call `grokclassfn' at all.  */
  6271. static tree
  6272. grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, check)
  6273.      tree ctype, type;
  6274.      tree declarator;
  6275.      int virtualp;
  6276.      enum overload_flags flags;
  6277.      tree quals, raises;
  6278.      int check;
  6279. {
  6280.   tree cname, decl;
  6281.   int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
  6282.  
  6283.   if (ctype)
  6284.     cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
  6285.       ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
  6286.   else
  6287.     cname = NULL_TREE;
  6288.  
  6289.   if (raises)
  6290.     {
  6291.       type = build_exception_variant (ctype, type, raises);
  6292.       raises = TYPE_RAISES_EXCEPTIONS (type);
  6293.     }
  6294.   decl = build_lang_decl (FUNCTION_DECL, declarator, type);
  6295.   /* propagate volatile out from type to decl */
  6296.   if (TYPE_VOLATILE (type))
  6297.       TREE_THIS_VOLATILE (decl) = 1;
  6298.   /* should probably propagate const out from type to decl I bet (mrs) */
  6299.   if (staticp)
  6300.     {
  6301.       DECL_STATIC_FUNCTION_P (decl) = 1;
  6302.       DECL_CONTEXT (decl) = ctype;
  6303.       DECL_CLASS_CONTEXT (decl) = ctype;
  6304.     }
  6305.   DECL_EXTERNAL (decl) = 1;
  6306.   if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
  6307.     {
  6308.       error ("functions cannot have method qualifiers");
  6309.       quals = NULL_TREE;
  6310.     }
  6311.  
  6312.   /* Only two styles of delete's are valid. */
  6313.   if (declarator == ansi_opname[(int) DELETE_EXPR])
  6314.     {
  6315.       tree args = TYPE_ARG_TYPES (type);
  6316.       int style1, style2;
  6317.  
  6318.       if (ctype && args && TREE_CODE (type) == METHOD_TYPE)
  6319.     /* remove this */
  6320.     args = TREE_CHAIN (args);
  6321.      
  6322.       style1 = type_list_equal (args,
  6323.                 tree_cons (NULL_TREE, ptr_type_node,
  6324.                        void_list_node));
  6325.       style2 = style1 != 0 ? 0 :
  6326.     type_list_equal (args,
  6327.              tree_cons (NULL_TREE, ptr_type_node,
  6328.                     tree_cons (NULL_TREE, sizetype,
  6329.                            void_list_node)));
  6330.  
  6331.       if (ctype == NULL_TREE)
  6332.     {
  6333.       if (! style1)
  6334.         /* ANSI C++ June 5 1992 WP 12.5.5.2 */
  6335.         error ("global operator delete must be declared as taking a single argument of type void*");
  6336.     }
  6337.       else
  6338.     if (! style1 && ! style2)
  6339.       /* ANSI C++ June 5 1992 WP 12.5.4.1 */
  6340.       error ("operator delete cannot be overloaded");
  6341.     }
  6342.  
  6343.   /* Caller will do the rest of this.  */
  6344.   if (check < 0)
  6345.     return decl;
  6346.  
  6347.   if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
  6348.     {
  6349.       tree tmp;
  6350.       /* Just handle constructors here.  We could do this
  6351.      inside the following if stmt, but I think
  6352.      that the code is more legible by breaking this
  6353.      case out.  See comments below for what each of
  6354.      the following calls is supposed to do.  */
  6355.       DECL_CONSTRUCTOR_P (decl) = 1;
  6356.  
  6357.       grokclassfn (ctype, declarator, decl, flags, quals);
  6358.       if (check)
  6359.     check_classfn (ctype, declarator, decl, flags);
  6360.       grok_ctor_properties (ctype, decl);
  6361.       if (check == 0)
  6362.     {
  6363.       /* FIXME: this should only need to look at IDENTIFIER_GLOBAL_VALUE.  */
  6364.       tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
  6365.       if (tmp == 0)
  6366.         IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
  6367.       else if (TREE_CODE (tmp) != TREE_CODE (decl))
  6368.         error_with_decl (decl, "inconsistent declarations for `%s'");
  6369.       else
  6370.         {
  6371.           duplicate_decls (decl, tmp);
  6372.           decl = tmp;
  6373.         }
  6374.       make_decl_rtl (decl, NULL_TREE, 1);
  6375.     }
  6376.     }
  6377.   else
  6378.     {
  6379.       tree tmp;
  6380.  
  6381.       /* Function gets the ugly name, field gets the nice one.
  6382.      This call may change the type of the function (because
  6383.      of default parameters)!  */
  6384.       if (ctype != NULL_TREE)
  6385.     grokclassfn (ctype, cname, decl, flags, quals);
  6386.  
  6387.       if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
  6388.     grok_op_properties (decl, virtualp);
  6389.  
  6390.       if (ctype != NULL_TREE && check)
  6391.     check_classfn (ctype, cname, decl, flags);
  6392.  
  6393.       if (ctype == NULL_TREE || check)
  6394.     return decl;
  6395.  
  6396.       /* Now install the declaration of this function so that
  6397.      others may find it (esp. its DECL_FRIENDLIST).
  6398.      Pretend we are at top level, we will get true
  6399.      reference later, perhaps.
  6400.  
  6401.      FIXME: This should only need to look at IDENTIFIER_GLOBAL_VALUE.  */
  6402.       tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
  6403.       if (tmp == 0)
  6404.     IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
  6405.       else if (TREE_CODE (tmp) != TREE_CODE (decl))
  6406.     error_with_decl (decl, "inconsistent declarations for `%s'");
  6407.       else
  6408.     {
  6409.       duplicate_decls (decl, tmp);
  6410.       decl = tmp;
  6411.     }
  6412.       make_decl_rtl (decl, NULL_TREE, 1);
  6413.  
  6414.       /* If this declaration supersedes the declaration of
  6415.      a method declared virtual in the base class, then
  6416.      mark this field as being virtual as well.  */
  6417.       {
  6418.     tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
  6419.     int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  6420.  
  6421.     for (i = 0; i < n_baselinks; i++)
  6422.       {
  6423.         tree base_binfo = TREE_VEC_ELT (binfos, i);
  6424.         if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo)) || flag_all_virtual == 1)
  6425.           {
  6426.         tmp = get_first_matching_virtual (base_binfo, decl,
  6427.                           flags == DTOR_FLAG);
  6428.         if (tmp)
  6429.           {
  6430.             /* The TMP we really want is the one from the deepest
  6431.                baseclass on this path, taking care not to
  6432.                duplicate if we have already found it (via another
  6433.                path to its virtual baseclass.  */
  6434.             if (staticp)
  6435.               {
  6436.             error_with_decl (decl, "method `%s' may not be declared static");
  6437.             error_with_decl (tmp, "(since `%s' declared virtual in base class.)");
  6438.             break;
  6439.               }
  6440.             virtualp = 1;
  6441.  
  6442.             if ((TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (base_binfo))
  6443.              || TYPE_USES_MULTIPLE_INHERITANCE (ctype))
  6444.             && BINFO_TYPE (base_binfo) != DECL_CONTEXT (tmp))
  6445.               tmp = get_first_matching_virtual (TYPE_BINFO (DECL_CONTEXT (tmp)),
  6446.                             decl, flags == DTOR_FLAG);
  6447.             if (value_member (tmp, DECL_VINDEX (decl)) == NULL_TREE)
  6448.               {
  6449.             /* The argument types may have changed... */
  6450.             tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  6451.             tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
  6452.  
  6453.             argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
  6454.                         TREE_CHAIN (argtypes));
  6455.             /* But the return type has not.  */
  6456.             type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
  6457.             if (raises)
  6458.               {
  6459.                 type = build_exception_variant (ctype, type, raises);
  6460.                 raises = TYPE_RAISES_EXCEPTIONS (type);
  6461.               }
  6462.             TREE_TYPE (decl) = type;
  6463.             DECL_VINDEX (decl)
  6464.               = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
  6465.               }
  6466.           }
  6467.           }
  6468.       }
  6469.       }
  6470.       if (virtualp)
  6471.     {
  6472.       if (DECL_VINDEX (decl) == NULL_TREE)
  6473.         DECL_VINDEX (decl) = error_mark_node;
  6474.       IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
  6475.       if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
  6476.           /* If this function is derived from a template, don't
  6477.          make it public.  This shouldn't be here, but there's
  6478.          no good way to override the interface pragmas for one
  6479.          function or class only.  Bletch.  */
  6480.           && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE
  6481.           && (write_virtuals == 2
  6482.           || (write_virtuals == 3
  6483.               && ! CLASSTYPE_INTERFACE_UNKNOWN (ctype))))
  6484.         TREE_PUBLIC (decl) = 1;
  6485.     }
  6486.     }
  6487.   return decl;
  6488. }
  6489.  
  6490. static tree
  6491. grokvardecl (ctype, type, declarator, specbits, initialized)
  6492.      tree ctype, type;
  6493.      tree declarator;
  6494.      int specbits, initialized;
  6495. {
  6496.   tree decl;
  6497.  
  6498.   if (TREE_CODE (type) == OFFSET_TYPE)
  6499.     {
  6500.       /* If you declare a static member so that it
  6501.      can be initialized, the code will reach here.  */
  6502.       tree field = lookup_field (TYPE_OFFSET_BASETYPE (type),
  6503.                  declarator, 0, 0);
  6504.       if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
  6505.     {
  6506.       tree basetype = TYPE_OFFSET_BASETYPE (type);
  6507.       error ("`%s' is not a static member of class `%s'",
  6508.          IDENTIFIER_POINTER (declarator),
  6509.          TYPE_NAME_STRING (basetype));
  6510.       type = TREE_TYPE (type);
  6511.       decl = build_lang_field_decl (VAR_DECL, declarator, type);
  6512.       DECL_CONTEXT (decl) = basetype;
  6513.       DECL_CLASS_CONTEXT (decl) = basetype;
  6514.     }
  6515.       else
  6516.     {
  6517.       tree f_type = TREE_TYPE (field);
  6518.       tree o_type = TREE_TYPE (type);
  6519.  
  6520.       if (TYPE_SIZE (f_type) == NULL_TREE)
  6521.         {
  6522.           if (TREE_CODE (f_type) != TREE_CODE (o_type)
  6523.           || (TREE_CODE (f_type) == ARRAY_TYPE
  6524.               && TREE_TYPE (f_type) != TREE_TYPE (o_type)))
  6525.         error ("redeclaration of type for `%s'",
  6526.                IDENTIFIER_POINTER (declarator));
  6527.           else if (TYPE_SIZE (o_type) != NULL_TREE)
  6528.         TREE_TYPE (field) = type;
  6529.         }
  6530.       else if (f_type != o_type)
  6531.         error ("redeclaration of type for `%s'",
  6532.            IDENTIFIER_POINTER (declarator));
  6533.       decl = field;
  6534.       if (initialized && DECL_INITIAL (decl)
  6535.           /* Complain about multiply-initialized
  6536.          member variables, but don't be faked
  6537.          out if initializer is faked up from `empty_init_node'.  */
  6538.           && (TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
  6539.           || CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) != NULL_TREE))
  6540.         error_with_aggr_type (DECL_CONTEXT (decl),
  6541.                   "multiple initializations of static member `%s::%s'",
  6542.                   IDENTIFIER_POINTER (DECL_NAME (decl)));
  6543.     }
  6544.     }
  6545.   else decl = build_decl (VAR_DECL, declarator, type);
  6546.  
  6547.   if (specbits & (1 << (int) RID_EXTERN))
  6548.     {
  6549.       DECL_THIS_EXTERN (decl) = 1;
  6550.       DECL_EXTERNAL (decl) = !initialized;
  6551.     }
  6552.  
  6553.   /* In class context, static means one per class,
  6554.      public visibility, and static storage.  */
  6555.   if (DECL_FIELD_CONTEXT (decl) != 0
  6556.       && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
  6557.     {
  6558.       TREE_PUBLIC (decl) = 1;
  6559.       TREE_STATIC (decl) = 1;
  6560.       DECL_EXTERNAL (decl) = !initialized;
  6561.     }
  6562.   /* At top level, either `static' or no s.c. makes a definition
  6563.      (perhaps tentative), and absence of `static' makes it public.  */
  6564.   else if (current_binding_level == global_binding_level)
  6565.     {
  6566.       TREE_PUBLIC (decl) = !(specbits & (1 << (int) RID_STATIC));
  6567.       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
  6568.     }
  6569.   /* Not at top level, only `static' makes a static definition.  */
  6570.   else
  6571.     {
  6572.       TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
  6573.       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
  6574.     }
  6575.   return decl;
  6576. }
  6577.  
  6578. /* Given declspecs and a declarator,
  6579.    determine the name and type of the object declared
  6580.    and construct a ..._DECL node for it.
  6581.    (In one case we can return a ..._TYPE node instead.
  6582.     For invalid input we sometimes return 0.)
  6583.  
  6584.    DECLSPECS is a chain of tree_list nodes whose value fields
  6585.     are the storage classes and type specifiers.
  6586.  
  6587.    DECL_CONTEXT says which syntactic context this declaration is in:
  6588.      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
  6589.      FUNCDEF for a function definition.  Like NORMAL but a few different
  6590.       error messages in each case.  Return value may be zero meaning
  6591.       this definition is too screwy to try to parse.
  6592.      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
  6593.       handle member functions (which have FIELD context).
  6594.       Return value may be zero meaning this definition is too screwy to
  6595.       try to parse.
  6596.      PARM for a parameter declaration (either within a function prototype
  6597.       or before a function body).  Make a PARM_DECL, or return void_type_node.
  6598.      TYPENAME if for a typename (in a cast or sizeof).
  6599.       Don't make a DECL node; just return the ..._TYPE node.
  6600.      FIELD for a struct or union field; make a FIELD_DECL.
  6601.      BITFIELD for a field with specified width.
  6602.    INITIALIZED is 1 if the decl has an initializer.
  6603.  
  6604.    In the TYPENAME case, DECLARATOR is really an absolute declarator.
  6605.    It may also be so in the PARM case, for a prototype where the
  6606.    argument type is specified but not the name.
  6607.  
  6608.    This function is where the complicated C meanings of `static'
  6609.    and `extern' are interpreted.
  6610.  
  6611.    For C++, if there is any monkey business to do, the function which
  6612.    calls this one must do it, i.e., prepending instance variables,
  6613.    renaming overloaded function names, etc.
  6614.  
  6615.    Note that for this C++, it is an error to define a method within a class
  6616.    which does not belong to that class.
  6617.  
  6618.    Except in the case where SCOPE_REFs are implicitly known (such as
  6619.    methods within a class being redundantly qualified),
  6620.    declarations which involve SCOPE_REFs are returned as SCOPE_REFs
  6621.    (class_name::decl_name).  The caller must also deal with this.
  6622.  
  6623.    If a constructor or destructor is seen, and the context is FIELD,
  6624.    then the type gains the attribute TREE_HAS_x.  If such a declaration
  6625.    is erroneous, NULL_TREE is returned.
  6626.  
  6627.    QUALS is used only for FUNCDEF and MEMFUNCDEF cases.  For a member
  6628.    function, these are the qualifiers to give to the `this' pointer.
  6629.  
  6630.    May return void_type_node if the declarator turned out to be a friend.
  6631.    See grokfield for details.  */
  6632.  
  6633. enum return_types { return_normal, return_ctor, return_dtor, return_conversion, };
  6634.  
  6635. tree
  6636. grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
  6637.      tree declspecs;
  6638.      tree declarator;
  6639.      enum decl_context decl_context;
  6640.      int initialized;
  6641.      tree raises;
  6642. {
  6643.   extern int current_class_depth;
  6644.  
  6645.   int specbits = 0;
  6646.   int nclasses = 0;
  6647.   tree spec;
  6648.   tree type = NULL_TREE;
  6649.   int longlong = 0;
  6650.   int constp;
  6651.   int volatilep;
  6652.   int virtualp, friendp, inlinep, staticp;
  6653. #ifdef APPLE_HAX
  6654.   /* Flag to detect a pascal declaration of a function or variable. */
  6655.   int pascalp = 0;
  6656. #endif /* APPLE_HAX */
  6657.   int explicit_int = 0;
  6658.   int explicit_char = 0;
  6659.   tree typedef_decl = 0;
  6660.   char *name;
  6661.   tree typedef_type = 0;
  6662.   int funcdef_flag = 0;
  6663.   enum tree_code innermost_code = ERROR_MARK;
  6664.   int bitfield = 0;
  6665.   int size_varies = 0;
  6666.   /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
  6667.      All FIELD_DECLs we build here have `init' put into their DECL_INITIAL.  */
  6668.   tree init = 0;
  6669.  
  6670.   /* Keep track of what sort of function is being processed
  6671.      so that we can warn about default return values, or explicit
  6672.      return values which do not match prescribed defaults.  */
  6673.   enum return_types return_type = return_normal;
  6674.  
  6675.   tree dname = NULL_TREE;
  6676.   tree ctype = current_class_type;
  6677.   tree ctor_return_type = NULL_TREE;
  6678.   enum overload_flags flags = NO_SPECIAL;
  6679.   int seen_scope_ref = 0;
  6680.   tree quals = 0;
  6681.  
  6682.   if (decl_context == FUNCDEF)
  6683.     funcdef_flag = 1, decl_context = NORMAL;
  6684.   else if (decl_context == MEMFUNCDEF)
  6685.     funcdef_flag = -1, decl_context = FIELD;
  6686.   else if (decl_context == BITFIELD)
  6687.     bitfield = 1, decl_context = FIELD;
  6688.  
  6689.   if (flag_traditional && allocation_temporary_p ())
  6690.     end_temporary_allocation ();
  6691.  
  6692.   /* Look inside a declarator for the name being declared
  6693.      and get it as a string, for an error message.  */
  6694.   {
  6695.     tree type, last = 0;
  6696.     register tree decl = declarator;
  6697.     name = 0;
  6698.  
  6699.     /* If we see something of the form `aggr_type xyzzy (a, b, c)'
  6700.        it is either an old-style function declaration or a call to
  6701.        a constructor.  The following conditional makes recognizes this
  6702.        case as being a call to a constructor.  Too bad if it is not.  */
  6703.  
  6704.     /* For Doug Lea, also grok `aggr_type xyzzy (a, b, c)[10][10][10]'.  */
  6705.     while (decl && TREE_CODE (decl) == ARRAY_REF)
  6706.       {
  6707.     last = decl;
  6708.     decl = TREE_OPERAND (decl, 0);
  6709.       }
  6710.  
  6711.     if (decl && declspecs
  6712.         && TREE_CODE (decl) == CALL_EXPR
  6713.         && TREE_OPERAND (decl, 0)
  6714.         && (TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
  6715.         || TREE_CODE (TREE_OPERAND (decl, 0)) == SCOPE_REF))
  6716.       {
  6717.         type = TREE_CODE (TREE_VALUE (declspecs)) == IDENTIFIER_NODE
  6718.           ? lookup_name (TREE_VALUE (declspecs), 1) :
  6719.         (IS_AGGR_TYPE (TREE_VALUE (declspecs))
  6720.          ? TYPE_NAME (TREE_VALUE (declspecs)) : NULL_TREE);
  6721.  
  6722.         if (type && TREE_CODE (type) == TYPE_DECL
  6723.             && IS_AGGR_TYPE (TREE_TYPE (type))
  6724.             && parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
  6725.           {
  6726.             if (decl_context == FIELD
  6727.                 && TREE_CHAIN (TREE_OPERAND (decl, 1)))
  6728.               {
  6729.                 /* That was an initializer list.  */
  6730.                 sorry ("initializer lists for field declarations");
  6731.                 decl = TREE_OPERAND (decl, 0);
  6732.         if (last)
  6733.           {
  6734.             TREE_OPERAND (last, 0) = decl;
  6735.             decl = declarator;
  6736.           }
  6737.                 declarator = decl;
  6738.                 init = error_mark_node;
  6739.                 goto bot;
  6740.               }
  6741.             else
  6742.               {
  6743.         init = TREE_OPERAND (decl, 1);
  6744.         if (last)
  6745.           {
  6746.             TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0);
  6747.             if (pedantic && init)
  6748.               {
  6749.               error ("arrays cannot take initializers");
  6750.               init = error_mark_node;
  6751.             }
  6752.           }
  6753.         else
  6754.           declarator = TREE_OPERAND (declarator, 0);
  6755.         decl = start_decl (declarator, declspecs, 1, NULL_TREE);
  6756.         finish_decl (decl, init, NULL_TREE, 1);
  6757.         return 0;
  6758.               }
  6759.           }
  6760.  
  6761.         if (parmlist_is_random (TREE_OPERAND (decl, 1)))
  6762.           {
  6763.         decl = TREE_OPERAND (decl, 0);
  6764.         if (TREE_CODE (decl) == SCOPE_REF)
  6765.           {
  6766.         if (TREE_COMPLEXITY (decl))
  6767.           my_friendly_abort (15);
  6768.         decl = TREE_OPERAND (decl, 1);
  6769.           }
  6770.         if (TREE_CODE (decl) == IDENTIFIER_NODE)
  6771.           name = IDENTIFIER_POINTER (decl);
  6772.         if (name)
  6773.           error ("bad parameter list specification for function `%s'",
  6774.              name);
  6775.         else
  6776.           error ("bad parameter list specification for function");
  6777.             return void_type_node;
  6778.           }
  6779.       bot:
  6780.         ;
  6781.       }
  6782.     else
  6783.       /* It didn't look like we thought it would, leave the ARRAY_REFs on.  */
  6784.       decl = declarator;
  6785.  
  6786.     while (decl)
  6787.       switch (TREE_CODE (decl))
  6788.         {
  6789.     case COND_EXPR:
  6790.       ctype = NULL_TREE;
  6791.       decl = TREE_OPERAND (decl, 0);
  6792.       break;
  6793.  
  6794.     case BIT_NOT_EXPR:      /* for C++ destructors!  */
  6795.       {
  6796.         tree name = TREE_OPERAND (decl, 0);
  6797.         tree rename = NULL_TREE;
  6798.  
  6799.         my_friendly_assert (flags == NO_SPECIAL, 152);
  6800.         flags = DTOR_FLAG;
  6801.         return_type = return_dtor;
  6802.         my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
  6803.         if (ctype == NULL_TREE)
  6804.           {
  6805.         if (current_class_type == NULL_TREE)
  6806.           {
  6807.             error ("destructors must be member functions");
  6808.             flags = NO_SPECIAL;
  6809.           }
  6810.         else
  6811.           {
  6812.             tree t = constructor_name (current_class_name);
  6813.             if (t != name)
  6814.               rename = t;
  6815.           }
  6816.           }
  6817.         else
  6818.           {
  6819.         tree t = constructor_name (ctype);
  6820.         if (t != name)
  6821.           rename = t;
  6822.           }
  6823.  
  6824.         if (rename)
  6825.           {
  6826.         error ("destructor `%s' must match class name `%s'",
  6827.                IDENTIFIER_POINTER (name),
  6828.                IDENTIFIER_POINTER (rename));
  6829.         TREE_OPERAND (decl, 0) = rename;
  6830.           }
  6831.         decl = name;
  6832.       }
  6833.       break;
  6834.  
  6835.     case ADDR_EXPR:         /* C++ reference declaration */
  6836.       /* fall through */
  6837.     case ARRAY_REF:
  6838.     case INDIRECT_REF:
  6839.       ctype = NULL_TREE;
  6840.       innermost_code = TREE_CODE (decl);
  6841.       decl = TREE_OPERAND (decl, 0);
  6842.       break;
  6843.  
  6844.     case CALL_EXPR:
  6845.       innermost_code = TREE_CODE (decl);
  6846.       decl = TREE_OPERAND (decl, 0);
  6847.       if (decl_context == FIELD && ctype == NULL_TREE)
  6848.         ctype = current_class_type;
  6849.       if (ctype != NULL_TREE
  6850.           && decl != NULL_TREE && flags != DTOR_FLAG
  6851.           && decl == constructor_name (ctype))
  6852.         {
  6853.           return_type = return_ctor;
  6854.           ctor_return_type = ctype;
  6855.         }
  6856.       ctype = NULL_TREE;
  6857.       break;
  6858.  
  6859.     case IDENTIFIER_NODE:
  6860.       dname = decl;
  6861.       name = IDENTIFIER_POINTER (decl);
  6862.       decl = 0;
  6863.       break;
  6864.  
  6865.     case RECORD_TYPE:
  6866.     case UNION_TYPE:
  6867.     case ENUMERAL_TYPE:
  6868.       /* Parse error puts this typespec where
  6869.          a declarator should go.  */
  6870.       error ("declarator name missing");
  6871.       dname = TYPE_NAME (decl);
  6872.       if (dname && TREE_CODE (dname) == TYPE_DECL)
  6873.         dname = DECL_NAME (dname);
  6874.       name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
  6875.       declspecs = temp_tree_cons (NULL_TREE, decl, declspecs);
  6876.       decl = 0;
  6877.       break;
  6878.  
  6879.     case TYPE_EXPR:
  6880.       if (ctype == NULL_TREE)
  6881.         {
  6882.           /* ANSI C++ June 5 1992 WP 12.3.2 only describes
  6883.          conversion functions in terms of being declared
  6884.          as a member function.  */
  6885.           error ("operator `%s' must be declared as a member",
  6886.              IDENTIFIER_POINTER (TREE_VALUE (TREE_TYPE (decl))));
  6887.           return NULL_TREE;
  6888.         }
  6889.           
  6890.       ctype = NULL_TREE;
  6891.       my_friendly_assert (flags == NO_SPECIAL, 154);
  6892.       flags = TYPENAME_FLAG;
  6893.       name = "operator <typename>";
  6894.       /* Go to the absdcl.  */
  6895.       decl = TREE_OPERAND (decl, 0);
  6896.       return_type = return_conversion;
  6897.       break;
  6898.  
  6899.       /* C++ extension */
  6900.     case SCOPE_REF:
  6901.       if (seen_scope_ref == 1)
  6902.         error ("multiple `::' terms in declarator invalid");
  6903.       seen_scope_ref += 1;
  6904.       {
  6905.         /* Perform error checking, and convert class names to types.
  6906.            We may call grokdeclarator multiple times for the same
  6907.            tree structure, so only do the conversion once.  In this
  6908.            case, we have exactly what we want for `ctype'.  */
  6909.         tree cname = TREE_OPERAND (decl, 0);
  6910.         if (cname == NULL_TREE)
  6911.           ctype = NULL_TREE;
  6912.         /* Can't use IS_AGGR_TYPE because CNAME might not be a type.  */
  6913.         else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname))
  6914.              || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE)
  6915.           ctype = cname;
  6916.         else if (! is_aggr_typedef (cname, 1))
  6917.           {
  6918.         TREE_OPERAND (decl, 0) = 0;
  6919.           }
  6920.         /* Must test TREE_OPERAND (decl, 1), in case user gives
  6921.            us `typedef (class::memfunc)(int); memfunc *memfuncptr;'  */
  6922.         else if (TREE_OPERAND (decl, 1)
  6923.              && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
  6924.           {
  6925.         TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname);
  6926.           }
  6927.         else if (ctype == NULL_TREE)
  6928.           {
  6929.         ctype = IDENTIFIER_TYPE_VALUE (cname);
  6930.         TREE_OPERAND (decl, 0) = ctype;
  6931.           }
  6932.         else if (TREE_COMPLEXITY (decl) == current_class_depth)
  6933.           TREE_OPERAND (decl, 0) = ctype;
  6934.         else
  6935.           {
  6936.         if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname), ctype))
  6937.           {
  6938.             error ("type `%s' is not derived from type `%s'",
  6939.                IDENTIFIER_POINTER (cname),
  6940.                TYPE_NAME_STRING (ctype));
  6941.             TREE_OPERAND (decl, 0) = 0;
  6942.           }
  6943.         else
  6944.           {
  6945.             ctype = IDENTIFIER_TYPE_VALUE (cname);
  6946.             TREE_OPERAND (decl, 0) = ctype;
  6947.           }
  6948.           }
  6949.  
  6950.         decl = TREE_OPERAND (decl, 1);
  6951.         if (ctype)
  6952.           {
  6953.         if (TREE_CODE (decl) == IDENTIFIER_NODE
  6954.             && constructor_name (ctype) == decl)
  6955.           {
  6956.             return_type = return_ctor;
  6957.             ctor_return_type = ctype;
  6958.           }
  6959.         else if (TREE_CODE (decl) == BIT_NOT_EXPR
  6960.              && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
  6961.              && constructor_name (ctype) == TREE_OPERAND (decl, 0))
  6962.           {
  6963.             return_type = return_dtor;
  6964.             ctor_return_type = ctype;
  6965.             flags = DTOR_FLAG;
  6966.             decl = TREE_OPERAND (decl, 0);
  6967.           }
  6968.           }
  6969.       }
  6970.       break;
  6971.  
  6972.     case ERROR_MARK:
  6973.       decl = NULL_TREE;
  6974.       break;
  6975.  
  6976.     default:
  6977.       my_friendly_assert (0, 155);
  6978.     }
  6979.     if (name == 0)
  6980.       name = "type name";
  6981.   }
  6982.  
  6983.   /* A function definition's declarator must have the form of
  6984.      a function declarator.  */
  6985.  
  6986.   if (funcdef_flag && innermost_code != CALL_EXPR)
  6987.     return 0;
  6988.  
  6989.   /* Anything declared one level down from the top level
  6990.      must be one of the parameters of a function
  6991.      (because the body is at least two levels down).  */
  6992.  
  6993.   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
  6994.      by not allowing C++ class definitions to specify their parameters
  6995.      with xdecls (must be spec.d in the parmlist).
  6996.  
  6997.      Since we now wait to push a class scope until we are sure that
  6998.      we are in a legitimate method context, we must set oldcname
  6999.      explicitly (since current_class_name is not yet alive).  */
  7000.  
  7001.   if (decl_context == NORMAL
  7002.       && current_binding_level->level_chain == global_binding_level)
  7003.     decl_context = PARM;
  7004.  
  7005.   /* Look through the decl specs and record which ones appear.
  7006.      Some typespecs are defined as built-in typenames.
  7007.      Others, the ones that are modifiers of other types,
  7008.      are represented by bits in SPECBITS: set the bits for
  7009.      the modifiers that appear.  Storage class keywords are also in SPECBITS.
  7010.  
  7011.      If there is a typedef name or a type, store the type in TYPE.
  7012.      This includes builtin typedefs such as `int'.
  7013.  
  7014.      Set EXPLICIT_INT if the type is `int' or `char' and did not
  7015.      come from a user typedef.
  7016.  
  7017.      Set LONGLONG if `long' is mentioned twice.
  7018.  
  7019.      For C++, constructors and destructors have their own fast treatment.  */
  7020.  
  7021.   for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
  7022.     {
  7023.       register int i;
  7024.       register tree id = TREE_VALUE (spec);
  7025.  
  7026.       /* Certain parse errors slip through.  For example,
  7027.      `int class;' is not caught by the parser. Try
  7028.      weakly to recover here.  */
  7029.       if (TREE_CODE (spec) != TREE_LIST)
  7030.     return 0;
  7031.  
  7032.       if (TREE_CODE (id) == IDENTIFIER_NODE)
  7033.     {
  7034.       if (id == ridpointers[(int) RID_INT])
  7035.         {
  7036.           if (type)
  7037.         error ("extraneous `int' ignored");
  7038.           else
  7039.         {
  7040.           explicit_int = 1;
  7041.           type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
  7042.         }
  7043.           goto found;
  7044.         }
  7045.       if (id == ridpointers[(int) RID_CHAR])
  7046.         {
  7047.           if (type)
  7048.         error ("extraneous `char' ignored");
  7049.           else
  7050.         {
  7051.           explicit_char = 1;
  7052.           type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
  7053.         }
  7054.           goto found;
  7055.         }
  7056.       if (id == ridpointers[(int) RID_WCHAR])
  7057.         {
  7058.           if (type)
  7059.         error ("extraneous `__wchar_t' ignored");
  7060.           else
  7061.         {
  7062.           type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
  7063.         }
  7064.           goto found;
  7065.         }
  7066.       /* C++ aggregate types.  */
  7067.       if (IDENTIFIER_HAS_TYPE_VALUE (id))
  7068.         {
  7069.           if (type)
  7070.         error ("multiple declarations `%s' and `%s'",
  7071.                IDENTIFIER_POINTER (type),
  7072.                IDENTIFIER_POINTER (id));
  7073.           else
  7074.         type = IDENTIFIER_TYPE_VALUE (id);
  7075.           goto found;
  7076.         }
  7077.  
  7078.       for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
  7079.         {
  7080.           if (ridpointers[i] == id)
  7081.         {
  7082.           if (i == (int) RID_LONG && specbits & (1<<i))
  7083.             {
  7084.               if (pedantic)
  7085.             pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
  7086.               else if (longlong)
  7087.                 error ("`long long long' is too long for GCC");
  7088.               else
  7089.             longlong = 1;
  7090.             }
  7091.           else if (specbits & (1 << i))
  7092.             warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
  7093.           specbits |= 1 << i;
  7094.           goto found;
  7095.         }
  7096.         }
  7097.     }
  7098.       if (type)
  7099.     error ("two or more data types in declaration of `%s'", name);
  7100.       else if (TREE_CODE (id) == IDENTIFIER_NODE)
  7101.     {
  7102.       register tree t = lookup_name (id, 1);
  7103.       if (!t || TREE_CODE (t) != TYPE_DECL)
  7104.         error ("`%s' fails to be a typedef or built in type",
  7105.            IDENTIFIER_POINTER (id));
  7106.       else
  7107.         {
  7108.           type = TREE_TYPE (t);
  7109.           typedef_decl = t;
  7110.         }
  7111.     }
  7112.       else if (TREE_CODE (id) != ERROR_MARK)
  7113.     /* Can't change CLASS nodes into RECORD nodes here!  */
  7114.     type = id;
  7115.  
  7116.     found: {}
  7117.     }
  7118.  
  7119.   typedef_type = type;
  7120.  
  7121.   /* No type at all: default to `int', and set EXPLICIT_INT
  7122.      because it was not a user-defined typedef.  */
  7123.  
  7124.   if (type == 0)
  7125.     {
  7126.       explicit_int = -1;
  7127.       if (return_type == return_dtor)
  7128.     type = void_type_node;
  7129.       else if (return_type == return_ctor)
  7130.     type = TYPE_POINTER_TO (ctor_return_type);
  7131.       else
  7132.     {
  7133.       if (funcdef_flag && explicit_warn_return_type
  7134.           && return_type == return_normal
  7135.           && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  7136.                 | (1 << (int) RID_SIGNED) | (1 << (int) RID_UNSIGNED))))
  7137.         warn_about_return_type = 1;
  7138.       /* Save warning until we know what is really going on.  */
  7139.       type = integer_type_node;
  7140.     }
  7141.     }
  7142.   else if (return_type == return_dtor)
  7143.     {
  7144.       error ("return type specification for destructor invalid");
  7145.       type = void_type_node;
  7146.     }
  7147.   else if (return_type == return_ctor)
  7148.     {
  7149.       error ("return type specification for constructor invalid");
  7150.       type = TYPE_POINTER_TO (ctor_return_type);
  7151.     }
  7152.   else if ((specbits & (1 << (int) RID_FRIEND))
  7153.        && IS_AGGR_TYPE (type)
  7154.        && ! TYPE_BEING_DEFINED (type)
  7155.        && TYPE_SIZE (type) == NULL_TREE
  7156.        && ! ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))
  7157.        && current_function_decl == NULL_TREE
  7158.        && decl_context != PARM)
  7159.     {
  7160.       /* xref_tag will make friend class declarations look like
  7161.      nested class declarations.  Retroactively change that
  7162.      if the type has not yet been defined.
  7163.  
  7164.      ??? ANSI C++ doesn't say what to do in this case yet.  */
  7165.       globalize_nested_type (type);
  7166.     }
  7167.  
  7168.   ctype = NULL_TREE;
  7169.  
  7170.   /* Now process the modifiers that were specified
  7171.      and check for invalid combinations.  */
  7172.  
  7173.   /* Long double is a special combination.  */
  7174.  
  7175.   if ((specbits & 1 << (int) RID_LONG)
  7176.       && TYPE_MAIN_VARIANT (type) == double_type_node)
  7177.     {
  7178.       specbits &= ~ (1 << (int) RID_LONG);
  7179.       type = build_type_variant (long_double_type_node, TYPE_READONLY (type),
  7180.                  TYPE_VOLATILE (type));
  7181.     }
  7182.  
  7183.   /* Check all other uses of type modifiers.  */
  7184.  
  7185.   if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  7186.           | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
  7187.     {
  7188.       int ok = 0;
  7189.  
  7190.       if (TREE_CODE (type) == REAL_TYPE)
  7191.     error ("short, signed or unsigned invalid for `%s'", name);
  7192.       else if (TREE_CODE (type) != INTEGER_TYPE || type == wchar_type_node)
  7193.     error ("long, short, signed or unsigned invalid for `%s'", name);
  7194.       else if ((specbits & 1 << (int) RID_LONG)
  7195.            && (specbits & 1 << (int) RID_SHORT))
  7196.     error ("long and short specified together for `%s'", name);
  7197.       else if (((specbits & 1 << (int) RID_LONG)
  7198.         || (specbits & 1 << (int) RID_SHORT))
  7199.            && explicit_char)
  7200.     error ("long or short specified with char for `%s'", name);
  7201.       else if (((specbits & 1 << (int) RID_LONG)
  7202.         || (specbits & 1 << (int) RID_SHORT))
  7203.            && TREE_CODE (type) == REAL_TYPE)
  7204.     error ("long or short specified with floating type for `%s'", name);
  7205.       else if ((specbits & 1 << (int) RID_SIGNED)
  7206.            && (specbits & 1 << (int) RID_UNSIGNED))
  7207.     error ("signed and unsigned given together for `%s'", name);
  7208.       else
  7209.     {
  7210.       ok = 1;
  7211.       if (!explicit_int && !explicit_char && pedantic)
  7212.         {
  7213.           pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
  7214.                name);
  7215.           if (flag_pedantic_errors)
  7216.         ok = 0;
  7217.         }
  7218.     }
  7219.  
  7220.       /* Discard the type modifiers if they are invalid.  */
  7221.       if (! ok)
  7222.     {
  7223.       specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  7224.             | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED));
  7225.       longlong = 0;
  7226.     }
  7227.     }
  7228.  
  7229.   /* Decide whether an integer type is signed or not.
  7230.      Optionally treat bitfields as signed by default.  */
  7231.   if (specbits & 1 << (int) RID_UNSIGNED
  7232.       /* Traditionally, all bitfields are unsigned.  */
  7233.       || (bitfield && flag_traditional)
  7234.       || (bitfield && ! flag_signed_bitfields
  7235.       && (explicit_int || explicit_char
  7236.           /* A typedef for plain `int' without `signed'
  7237.          can be controlled just like plain `int'.  */
  7238.           || ! (typedef_decl != 0
  7239.             && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
  7240.       && TREE_CODE (type) != ENUMERAL_TYPE
  7241.       && !(specbits & 1 << (int) RID_SIGNED)))
  7242.     {
  7243.       if (longlong)
  7244.     type = long_long_unsigned_type_node;
  7245.       else if (specbits & 1 << (int) RID_LONG)
  7246.     type = long_unsigned_type_node;
  7247.       else if (specbits & 1 << (int) RID_SHORT)
  7248.     type = short_unsigned_type_node;
  7249.       else if (type == char_type_node)
  7250.     type = unsigned_char_type_node;
  7251.       else if (typedef_decl)
  7252.     type = unsigned_type (type);
  7253.       else
  7254.     type = unsigned_type_node;
  7255.     }
  7256.   else if ((specbits & 1 << (int) RID_SIGNED)
  7257.        && type == char_type_node)
  7258.     type = signed_char_type_node;
  7259.   else if (longlong)
  7260.     type = long_long_integer_type_node;
  7261.   else if (specbits & 1 << (int) RID_LONG)
  7262.     type = long_integer_type_node;
  7263.   else if (specbits & 1 << (int) RID_SHORT)
  7264.     type = short_integer_type_node;
  7265.  
  7266.   /* Set CONSTP if this declaration is `const', whether by
  7267.      explicit specification or via a typedef.
  7268.      Likewise for VOLATILEP.  */
  7269.  
  7270.   constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type);
  7271.   volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
  7272.   staticp = 0;
  7273.   inlinep = !! (specbits & (1 << (int) RID_INLINE));
  7274. #if 0/*def APPLE_HAX*/
  7275.   if(flag_apple) {
  7276.     /* Set a flag if the keyword `pascal' appeared in the declspecs. */
  7277.     pascalp = !! (specbits & (1 << (int) RID_PASCAL));
  7278.   }
  7279. #endif /* APPLE_HAX */
  7280.   if (constp > 1)
  7281.     warning ("duplicate `const'");
  7282.   if (volatilep > 1)
  7283.     warning ("duplicate `volatile'");
  7284.   virtualp = specbits & (1 << (int) RID_VIRTUAL);
  7285.   if (specbits & (1 << (int) RID_STATIC))
  7286.     staticp = 1 + (decl_context == FIELD);
  7287.  
  7288.   if (virtualp && staticp == 2)
  7289.     {
  7290.       error ("member `%s' cannot be declared both virtual and static", name);
  7291.       staticp = 0;
  7292.     }
  7293.   friendp = specbits & (1 << (int) RID_FRIEND);
  7294.   specbits &= ~ ((1 << (int) RID_VIRTUAL) | (1 << (int) RID_FRIEND));
  7295.  
  7296.   /* Warn if two storage classes are given. Default to `auto'.  */
  7297.  
  7298.   if (specbits)
  7299.     {
  7300.       if (specbits & 1 << (int) RID_STATIC) nclasses++;
  7301.       if (specbits & 1 << (int) RID_EXTERN) nclasses++;
  7302.       if (decl_context == PARM && nclasses > 0)
  7303.     error ("storage class specifiers invalid in parameter declarations");
  7304.       if (specbits & 1 << (int) RID_TYPEDEF)
  7305.     {
  7306.       if (decl_context == PARM)
  7307.         error ("typedef declaration invalid in parameter declaration");
  7308.       nclasses++;
  7309.     }
  7310.       if (specbits & 1 << (int) RID_AUTO) nclasses++;
  7311.       if (specbits & 1 << (int) RID_REGISTER) nclasses++;
  7312.     }
  7313.  
  7314.   /* Give error if `virtual' is used outside of class declaration.  */
  7315.   if (virtualp && current_class_name == NULL_TREE)
  7316.     {
  7317.       error ("virtual outside class declaration");
  7318.       virtualp = 0;
  7319.     }
  7320.  
  7321.   /* Warn about storage classes that are invalid for certain
  7322.      kinds of declarations (parameters, typenames, etc.).  */
  7323.  
  7324.   if (nclasses > 1)
  7325.     error ("multiple storage classes in declaration of `%s'", name);
  7326.   else if (decl_context != NORMAL && nclasses > 0)
  7327.     {
  7328.       if (decl_context == PARM
  7329.       && ((specbits & (1 << (int) RID_REGISTER)) | (1 << (int) RID_AUTO)))
  7330.     ;
  7331.       else if (decl_context == FIELD && (specbits & (1 << (int) RID_TYPEDEF)))
  7332.     {
  7333.       /* A typedef which was made in a class's scope.  */
  7334.       tree loc_typedecl;
  7335.       register int i = sizeof (struct lang_decl_flags) / sizeof (int);
  7336.       register int *pi;
  7337.  
  7338.       /* keep `grokdeclarator' from thinking we are in PARM context.  */
  7339.       pushlevel (0);
  7340.       loc_typedecl = start_decl (declarator, declspecs, initialized, NULL_TREE);
  7341.  
  7342.       pi = (int *) permalloc (sizeof (struct lang_decl_flags));
  7343.       while (i > 0)
  7344.         pi[--i] = 0;
  7345.       DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
  7346.       /* This poplevel conflicts with the popclass over in
  7347.          grokdeclarator.  See ``This popclass conflicts'' */
  7348.       poplevel (0, 0, 0);
  7349.  
  7350. #if 0
  7351.       if (TREE_CODE (TREE_TYPE (loc_typedecl)) == ENUMERAL_TYPE)
  7352.         {
  7353.           tree ref = lookup_tag (ENUMERAL_TYPE, DECL_NAME (loc_typedecl), current_binding_level, 0);
  7354.           if (! ref)
  7355.         pushtag (DECL_NAME (loc_typedecl), TREE_TYPE (loc_typedecl));
  7356.         }
  7357. #endif
  7358.       if (IDENTIFIER_CLASS_VALUE (DECL_NAME (loc_typedecl)))
  7359.         error_with_decl (loc_typedecl,
  7360.                  "typedef of `%s' in class scope hides previous declaration");
  7361. #if 0
  7362.       /* Must push this into scope via `pushdecl_class_level'.  */
  7363.       IDENTIFIER_CLASS_VALUE (DECL_NAME (loc_typedecl)) = loc_typedecl;
  7364. #endif
  7365.       return loc_typedecl;
  7366.     }
  7367.       else if (decl_context == FIELD
  7368.             /* C++ allows static class elements  */
  7369.             && (specbits & (1 << (int) RID_STATIC)))
  7370.      /* C++ also allows inlines and signed and unsigned elements,
  7371.         but in those cases we don't come in here.  */
  7372.     ;
  7373.       else
  7374.     {
  7375.       if (decl_context == FIELD)
  7376.         {
  7377.           tree tmp = TREE_OPERAND (declarator, 0);
  7378.           register int op = IDENTIFIER_OPNAME_P (tmp);
  7379.           error ("storage class specified for %s `%s'",
  7380.              op ? "member operator" : "structure field",
  7381.              op ? operator_name_string (tmp) : name);
  7382.         }
  7383.       else
  7384.         error ((decl_context == PARM
  7385.             ? "storage class specified for parameter `%s'"
  7386.             : "storage class specified for typename"), name);
  7387.       specbits &= ~ ((1 << (int) RID_REGISTER) | (1 << (int) RID_AUTO)
  7388.              | (1 << (int) RID_EXTERN));
  7389.     }
  7390.     }
  7391.   else if (specbits & 1 << (int) RID_EXTERN && initialized && !funcdef_flag)
  7392.     {
  7393.       if (current_binding_level == global_binding_level)
  7394.     warning ("`%s' initialized and declared `extern'", name);
  7395.       else
  7396.     error ("`%s' has both `extern' and initializer", name);
  7397.     }
  7398.   else if (specbits & 1 << (int) RID_EXTERN && funcdef_flag
  7399.        && current_binding_level != global_binding_level)
  7400.     error ("nested function `%s' declared `extern'", name);
  7401.   else if (current_binding_level == global_binding_level)
  7402.     {
  7403.       if (specbits & (1 << (int) RID_AUTO))
  7404.     error ("top-level declaration of `%s' specifies `auto'", name);
  7405. #if 0
  7406.       if (specbits & (1 << (int) RID_REGISTER))
  7407.     error ("top-level declaration of `%s' specifies `register'", name);
  7408. #endif
  7409. #if 0
  7410.       /* I'm not sure under what circumstances we should turn
  7411.      on the extern bit, and under what circumstances we should
  7412.      warn if other bits are turned on.  */
  7413.       if (decl_context == NORMAL
  7414.       && (specbits & (1 << (int) RID_EXTERN)) == 0
  7415.       && ! root_lang_context_p ())
  7416.     {
  7417.       specbits |= (1 << (int) RID_EXTERN);
  7418.     }
  7419. #endif
  7420.     }
  7421.  
  7422.   /* Now figure out the structure of the declarator proper.
  7423.      Descend through it, creating more complex types, until we reach
  7424.      the declared identifier (or NULL_TREE, in an absolute declarator).  */
  7425.  
  7426.   while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
  7427.     {
  7428.       /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
  7429.      an INDIRECT_REF (for *...),
  7430.      a CALL_EXPR (for ...(...)),
  7431.      an identifier (for the name being declared)
  7432.      or a null pointer (for the place in an absolute declarator
  7433.      where the name was omitted).
  7434.      For the last two cases, we have just exited the loop.
  7435.  
  7436.      For C++ it could also be
  7437.      a SCOPE_REF (for class :: ...).  In this case, we have converted
  7438.      sensible names to types, and those are the values we use to
  7439.      qualify the member name.
  7440.      an ADDR_EXPR (for &...),
  7441.      a BIT_NOT_EXPR (for destructors)
  7442.      a TYPE_EXPR (for operator typenames)
  7443.  
  7444.      At this point, TYPE is the type of elements of an array,
  7445.      or for a function to return, or for a pointer to point to.
  7446.      After this sequence of ifs, TYPE is the type of the
  7447.      array or function or pointer, and DECLARATOR has had its
  7448.      outermost layer removed.  */
  7449.  
  7450.       if (TREE_CODE (type) == ERROR_MARK)
  7451.     {
  7452.       if (TREE_CODE (declarator) == SCOPE_REF)
  7453.         declarator = TREE_OPERAND (declarator, 1);
  7454.       else
  7455.         declarator = TREE_OPERAND (declarator, 0);
  7456.       continue;
  7457.     }
  7458.       if (quals != NULL_TREE
  7459.       && (declarator == NULL_TREE
  7460.           || TREE_CODE (declarator) != SCOPE_REF))
  7461.     {
  7462.       if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
  7463.         ctype = TYPE_METHOD_BASETYPE (type);
  7464.       if (ctype != NULL_TREE)
  7465.         {
  7466. #if 0 /* not yet, should get fixed properly later */
  7467.           tree dummy = make_type_decl (NULL_TREE, type);
  7468. #else
  7469.           tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
  7470. #endif
  7471.           ctype = grok_method_quals (ctype, dummy, quals);
  7472.           type = TREE_TYPE (dummy);
  7473.           quals = NULL_TREE;
  7474.         }
  7475.     }
  7476.       switch (TREE_CODE (declarator))
  7477.     {
  7478.     case ARRAY_REF:
  7479.       maybe_globalize_type (type);
  7480.       {
  7481.         register tree itype = NULL_TREE;
  7482.         register tree size = TREE_OPERAND (declarator, 1);
  7483.  
  7484.         declarator = TREE_OPERAND (declarator, 0);
  7485.  
  7486.         /* Check for some types that there cannot be arrays of.  */
  7487.  
  7488.         if (TYPE_MAIN_VARIANT (type) == void_type_node)
  7489.           {
  7490.         error ("declaration of `%s' as array of voids", name);
  7491.         type = error_mark_node;
  7492.           }
  7493.  
  7494.         if (TREE_CODE (type) == FUNCTION_TYPE)
  7495.           {
  7496.         error ("declaration of `%s' as array of functions", name);
  7497.         type = error_mark_node;
  7498.           }
  7499.  
  7500.         if (size == error_mark_node)
  7501.           type = error_mark_node;
  7502.  
  7503.         if (type == error_mark_node)
  7504.           continue;
  7505.  
  7506.         if (size)
  7507.           {
  7508.         /* Must suspend_momentary here because the index
  7509.            type may need to live until the end of the function.
  7510.            For example, it is used in the declaration of a
  7511.            variable which requires destructing at the end of
  7512.            the function; then build_vec_delete will need this
  7513.            value.  */
  7514.         int yes = suspend_momentary ();
  7515.         /* might be a cast */
  7516.         if (TREE_CODE (size) == NOP_EXPR
  7517.             && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
  7518.           size = TREE_OPERAND (size, 0);
  7519.  
  7520.         /* If this is a template parameter, it'll be constant, but
  7521.            we don't know what the value is yet.  */
  7522.         if (TREE_CODE (size) == TEMPLATE_CONST_PARM)
  7523.           goto dont_grok_size;
  7524.  
  7525.         if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
  7526.             && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
  7527.           {
  7528.             error ("size of array `%s' has non-integer type", name);
  7529.             size = integer_one_node;
  7530.           }
  7531.         if (TREE_READONLY_DECL_P (size))
  7532.           size = decl_constant_value (size);
  7533.         if (pedantic && integer_zerop (size))
  7534.           pedwarn ("ANSI C++ forbids zero-size array `%s'", name);
  7535.         if (TREE_CONSTANT (size))
  7536.           {
  7537.             if (INT_CST_LT (size, integer_zero_node))
  7538.               {
  7539.             error ("size of array `%s' is negative", name);
  7540.             size = integer_one_node;
  7541.               }
  7542.             itype = build_index_type (size_binop (MINUS_EXPR, size,
  7543.                               integer_one_node));
  7544.           }
  7545.         else
  7546.           {
  7547.             if (pedantic)
  7548.               pedwarn ("ANSI C++ forbids variable-size array `%s'", name);
  7549.           dont_grok_size:
  7550.             itype = build_binary_op (MINUS_EXPR, size, integer_one_node);
  7551.             /* Make sure the array size remains visibly nonconstant
  7552.                even if it is (eg) a const variable with known value.  */
  7553.             size_varies = 1;
  7554.             itype = variable_size (itype);
  7555.             itype = build_index_type (itype);
  7556.           }
  7557.         resume_momentary (yes);
  7558.           }
  7559.  
  7560.         /* Build the array type itself.
  7561.            Merge any constancy or volatility into the target type.  */
  7562.  
  7563.         if (constp || volatilep)
  7564.           type = build_type_variant (type, constp, volatilep);
  7565.  
  7566. #if 0   /* don't clear these; leave them set so that the array type
  7567.        or the variable is itself const or volatile.  */
  7568.         constp = 0;
  7569.         volatilep = 0;
  7570. #endif
  7571.         type = build_cplus_array_type (type, itype);
  7572.         ctype = NULL_TREE;
  7573.       }
  7574.       break;
  7575.  
  7576.     case CALL_EXPR:
  7577.       maybe_globalize_type (type);
  7578.       {
  7579.         tree arg_types;
  7580.  
  7581.         /* Declaring a function type.
  7582.            Make sure we have a valid type for the function to return.  */
  7583. #if 0
  7584.         /* Is this an error?  Should they be merged into TYPE here?  */
  7585.         if (pedantic && (constp || volatilep))
  7586.           pedwarn ("function declared to return const or volatile result");
  7587. #else
  7588.         /* Merge any constancy or volatility into the target type
  7589.            for the pointer.  */
  7590.  
  7591.         if (constp || volatilep)
  7592.           {
  7593.         type = build_type_variant (type, constp, volatilep);
  7594.         if (IS_AGGR_TYPE (type))
  7595.           build_pointer_type (type);
  7596.         constp = 0;
  7597.         volatilep = 0;
  7598.           }
  7599. #endif
  7600.  
  7601.         /* Warn about some types functions can't return.  */
  7602.  
  7603.         if (TREE_CODE (type) == FUNCTION_TYPE)
  7604.           {
  7605.         error ("`%s' declared as function returning a function", name);
  7606.         type = integer_type_node;
  7607.           }
  7608.         if (TREE_CODE (type) == ARRAY_TYPE)
  7609.           {
  7610.         error ("`%s' declared as function returning an array", name);
  7611.         type = integer_type_node;
  7612.           }
  7613.  
  7614.         if (ctype == NULL_TREE
  7615.         && decl_context == FIELD
  7616.         && (friendp == 0 || dname == current_class_name))
  7617.           ctype = current_class_type;
  7618.  
  7619.         if (ctype && flags == TYPENAME_FLAG)
  7620.           TYPE_HAS_CONVERSION (ctype) = 1;
  7621.         if (ctype && constructor_name (ctype) == dname)
  7622.           {
  7623.         /* We are within a class's scope. If our declarator name
  7624.            is the same as the class name, and we are defining
  7625.            a function, then it is a constructor/destructor, and
  7626.            therefore returns a void type.  */
  7627.  
  7628.         if (flags == DTOR_FLAG)
  7629.           {
  7630.             /* ANSI C++ June 5 1992 WP 12.4.1.  A destructor may
  7631.                not be declared const or volatile.  A destructor
  7632.                may not be static.  */
  7633.             if (staticp == 2)
  7634.               error ("destructor cannot be static member function");
  7635.             if (TYPE_READONLY (type))
  7636.               {
  7637.             error ("destructors cannot be declared `const'");
  7638.             return void_type_node;
  7639.               }
  7640.             if (TYPE_VOLATILE (type))
  7641.               {
  7642.             error ("destructors cannot be declared `volatile'");
  7643.             return void_type_node;
  7644.               }
  7645.             if (decl_context == FIELD)
  7646.               {
  7647.             if (! member_function_or_else (ctype, current_class_type,
  7648.                                "destructor for alien class `%s' cannot be a member"))
  7649.               return void_type_node;
  7650.               }
  7651.           }
  7652.         else            /* it's a constructor. */
  7653.           {
  7654.             /* ANSI C++ June 5 1992 WP 12.1.2.  A constructor may
  7655.                not be declared const or volatile.  A constructor may
  7656.                not be virtual.  A constructor may not be static.  */
  7657.             if (staticp == 2)
  7658.               error ("constructor cannot be static member function");
  7659.             if (virtualp)
  7660.               {
  7661.             pedwarn ("constructors cannot be declared virtual");
  7662.             virtualp = 0;
  7663.               }
  7664.             if (TYPE_READONLY (type))
  7665.               {
  7666.             error ("constructors cannot be declared `const'");
  7667.             return void_type_node;
  7668.                }
  7669.             if (TYPE_VOLATILE (type))
  7670.               {
  7671.             error ("constructors cannot be declared `volatile'");
  7672.             return void_type_node;
  7673.               }
  7674.             if (specbits & ~((1 << (int) RID_INLINE)|(1 << (int) RID_STATIC)))
  7675.               error ("return value type specifier for constructor ignored");
  7676.             type = TYPE_POINTER_TO (ctype);
  7677.             if (decl_context == FIELD)
  7678.               {
  7679.             if (! member_function_or_else (ctype, current_class_type,
  7680.                                "constructor for alien class `%s' cannot be member"))
  7681.               return void_type_node;
  7682.             TYPE_HAS_CONSTRUCTOR (ctype) = 1;
  7683.             my_friendly_assert (return_type == return_ctor, 156);
  7684.               }
  7685.           }
  7686.         if (decl_context == FIELD)
  7687.           staticp = 0;
  7688.           }
  7689.         else if (friendp && virtualp)
  7690.           {
  7691.         /* Cannot be both friend and virtual.  */
  7692.         error ("virtual functions cannot be friends");
  7693.         specbits ^= (1 << (int) RID_FRIEND);
  7694.           }
  7695.  
  7696.         if (decl_context == NORMAL && friendp)
  7697.           error ("friend declaration not in class definition");
  7698.  
  7699.         /* Pick up type qualifiers which should be applied to `this'.  */
  7700.         quals = TREE_OPERAND (declarator, 2);
  7701.  
  7702.         /* Traditionally, declaring return type float means double.  */
  7703.  
  7704.         if (flag_traditional
  7705.         && TYPE_MAIN_VARIANT (type) == float_type_node)
  7706.           {
  7707.         type = build_type_variant (double_type_node,
  7708.                        TYPE_READONLY (type),
  7709.                        TYPE_VOLATILE (type));
  7710.           }
  7711.  
  7712.         /* Construct the function type and go to the next
  7713.            inner layer of declarator.  */
  7714.  
  7715.         {
  7716.           int funcdef_p;
  7717.           tree inner_parms = TREE_OPERAND (declarator, 1);
  7718.           tree inner_decl = TREE_OPERAND (declarator, 0);
  7719.  
  7720.           declarator = TREE_OPERAND (declarator, 0);
  7721.  
  7722.           if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
  7723.         inner_decl = TREE_OPERAND (inner_decl, 1);
  7724.  
  7725.           /* Say it's a definition only for the CALL_EXPR
  7726.          closest to the identifier.  */
  7727.           funcdef_p =
  7728.         (inner_decl &&
  7729.          (TREE_CODE (inner_decl) == IDENTIFIER_NODE
  7730.           || TREE_CODE (inner_decl) == TYPE_EXPR)) ? funcdef_flag : 0;
  7731.  
  7732.           arg_types = grokparms (inner_parms, funcdef_p);
  7733. #ifdef APPLE_HAX
  7734.       /* Bash the types of functions returning floats, last-ditch effort */
  7735.       if ((type == float_type_node || type == double_type_node) && flag_apple)
  7736.         type = long_double_type_node;
  7737. #endif /* APPLE_HAX */
  7738.         }
  7739.  
  7740.         if (declarator)
  7741.           {
  7742.         /* Get past destructors, etc.
  7743.            We know we have one because FLAGS will be non-zero.
  7744.  
  7745.            Complain about improper parameter lists here.  */
  7746.         if (TREE_CODE (declarator) == BIT_NOT_EXPR)
  7747.           {
  7748.             declarator = TREE_OPERAND (declarator, 0);
  7749.  
  7750.             if (strict_prototype == 0 && arg_types == NULL_TREE)
  7751.               arg_types = void_list_node;
  7752.             else if (arg_types == NULL_TREE
  7753.                  || arg_types != void_list_node)
  7754.               {
  7755.             error ("destructors cannot be specified with parameters");
  7756.             arg_types = void_list_node;
  7757.               }
  7758.           }
  7759.           }
  7760.         /* the top level const or volatile is attached semantically only
  7761.            to the function not the actual type. */
  7762.         if (TYPE_READONLY (type) || TYPE_VOLATILE (type))
  7763.           {
  7764.         int constp = TYPE_READONLY (type);
  7765.         int volatilep = TYPE_VOLATILE (type);
  7766.         type = build_function_type (TYPE_MAIN_VARIANT (type),
  7767.                         flag_traditional
  7768.                         ? 0
  7769.                         : arg_types);
  7770.         type = build_type_variant (type, constp, volatilep);
  7771.           }
  7772.         else
  7773.           type = build_function_type (type,
  7774.                       flag_traditional
  7775.                       ? 0
  7776.                       : arg_types);
  7777.       }
  7778.       break;
  7779.  
  7780.     case ADDR_EXPR:
  7781.     case INDIRECT_REF:
  7782.       maybe_globalize_type (type);
  7783.  
  7784.       /* Filter out pointers-to-references and references-to-references.
  7785.          We can get these if a TYPE_DECL is used.  */
  7786.  
  7787.       if (TREE_CODE (type) == REFERENCE_TYPE)
  7788.         {
  7789.           error ("cannot declare %s to references",
  7790.              TREE_CODE (declarator) == ADDR_EXPR
  7791.              ? "references" : "pointers");
  7792.           declarator = TREE_OPERAND (declarator, 0);
  7793.           continue;
  7794.         }
  7795.  
  7796.       /* Merge any constancy or volatility into the target type
  7797.          for the pointer.  */
  7798.  
  7799.       if (constp || volatilep)
  7800.         {
  7801.           type = build_type_variant (type, constp, volatilep);
  7802.           if (IS_AGGR_TYPE (type))
  7803.         build_pointer_type (type);
  7804.           constp = 0;
  7805.           volatilep = 0;
  7806.         }
  7807.  
  7808.       if (TREE_CODE (declarator) == ADDR_EXPR)
  7809.         {
  7810.           if (TREE_CODE (type) == FUNCTION_TYPE)
  7811.         {
  7812.           error ("cannot declare references to functions; use pointer to function instead");
  7813.           type = build_pointer_type (type);
  7814.         }
  7815.           else
  7816.         {
  7817.           if (TYPE_MAIN_VARIANT (type) == void_type_node)
  7818.             error ("invalid type: `void &'");
  7819.           else
  7820.             type = build_reference_type (type);
  7821.         }
  7822.         }
  7823.       else
  7824.         type = build_pointer_type (type);
  7825.  
  7826.       /* Process a list of type modifier keywords (such as
  7827.          const or volatile) that were given inside the `*' or `&'.  */
  7828.  
  7829.       if (TREE_TYPE (declarator))
  7830.         {
  7831.           register tree typemodlist;
  7832.           int erred = 0;
  7833.           for (typemodlist = TREE_TYPE (declarator); typemodlist;
  7834.            typemodlist = TREE_CHAIN (typemodlist))
  7835.         {
  7836.           if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
  7837.             constp++;
  7838.           else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
  7839.             volatilep++;
  7840.           else if (!erred)
  7841.             {
  7842.               erred = 1;
  7843.               error ("invalid type modifier within %s declarator",
  7844.                  TREE_CODE (declarator) == ADDR_EXPR
  7845.                  ? "reference" : "pointer");
  7846.             }
  7847.         }
  7848.           if (constp > 1)
  7849.         warning ("duplicate `const'");
  7850.           if (volatilep > 1)
  7851.         warning ("duplicate `volatile'");
  7852.         }
  7853.       declarator = TREE_OPERAND (declarator, 0);
  7854.       ctype = NULL_TREE;
  7855.       break;
  7856.  
  7857.     case SCOPE_REF:
  7858.       {
  7859.         /* We have converted type names to NULL_TREE if the
  7860.            name was bogus, or to a _TYPE node, if not.
  7861.  
  7862.            The variable CTYPE holds the type we will ultimately
  7863.            resolve to.  The code here just needs to build
  7864.            up appropriate member types.  */
  7865.         tree sname = TREE_OPERAND (declarator, 1);
  7866.         /* Destructors can have their visibilities changed as well.  */
  7867.         if (TREE_CODE (sname) == BIT_NOT_EXPR)
  7868.           sname = TREE_OPERAND (sname, 0);
  7869.  
  7870.         if (TREE_COMPLEXITY (declarator) == 0)
  7871.           /* This needs to be here, in case we are called
  7872.          multiple times.  */ ;
  7873.         else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
  7874.           /* don't fall out into global scope. Hides real bug? --eichin */ ;
  7875.         else if (TREE_COMPLEXITY (declarator) == current_class_depth)
  7876.           {
  7877.         TREE_COMPLEXITY (declarator) -= 1;
  7878.         /* This popclass conflicts with the poplevel over in
  7879.            grokdeclarator.  See ``This poplevel conflicts'' */
  7880.         popclass (1);
  7881.           }
  7882.         else
  7883.           my_friendly_abort (16);
  7884.  
  7885.         if (TREE_OPERAND (declarator, 0) == NULL_TREE)
  7886.           {
  7887.         /* We had a reference to a global decl, or
  7888.            perhaps we were given a non-aggregate typedef,
  7889.            in which case we cleared this out, and should just
  7890.            keep going as though it wasn't there.  */
  7891.         declarator = sname;
  7892.         continue;
  7893.           }
  7894.         ctype = TREE_OPERAND (declarator, 0);
  7895.  
  7896.         if (sname == NULL_TREE)
  7897.           goto done_scoping;
  7898.  
  7899.         if (TREE_CODE (sname) == IDENTIFIER_NODE)
  7900.           {
  7901.         /* This is the `standard' use of the scoping operator:
  7902.            basetype :: member .  */
  7903.  
  7904.         if (TYPE_MAIN_VARIANT (ctype) == current_class_type || friendp)
  7905.           {
  7906.             if (TREE_CODE (type) == FUNCTION_TYPE)
  7907.               type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  7908.                               TREE_TYPE (type), TYPE_ARG_TYPES (type));
  7909.             else
  7910.               {
  7911.             if (TYPE_MAIN_VARIANT (ctype) != current_class_type)
  7912.               {
  7913.                 error ("cannot declare member `%s::%s' within this class",
  7914.                    TYPE_NAME_STRING (ctype), name);
  7915.                 return void_type_node;
  7916.               }
  7917.             else if (extra_warnings)
  7918.               warning ("extra qualification `%s' on member `%s' ignored",
  7919.                    TYPE_NAME_STRING (ctype), name);
  7920.             type = build_offset_type (ctype, type);
  7921.               }
  7922.           }
  7923.         else if (TYPE_SIZE (ctype) != 0
  7924.              || (specbits & (1<<(int)RID_TYPEDEF)))
  7925.           {
  7926.             tree t;
  7927.             /* have to move this code elsewhere in this function.
  7928.                this code is used for i.e., typedef int A::M; M *pm; */
  7929.  
  7930.             if (explicit_int == -1 && decl_context == FIELD
  7931.             && funcdef_flag == 0)
  7932.               {
  7933.             /* The code in here should only be used to build
  7934.                stuff that will be grokked as visibility decls.  */
  7935.             t = lookup_field (ctype, sname, 0, 0);
  7936.             if (t)
  7937.               {
  7938.                 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
  7939.                 DECL_INITIAL (t) = init;
  7940.                 return t;
  7941.               }
  7942.             /* No such field, try member functions.  */
  7943.             t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0);
  7944.             if (t)
  7945.               {
  7946.                 if (flags == DTOR_FLAG)
  7947.                   t = TREE_VALUE (t);
  7948.                 else if (CLASSTYPE_METHOD_VEC (ctype)
  7949.                      && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
  7950.                   {
  7951.                 /* Don't include destructor with constructors.  */
  7952.                 t = DECL_CHAIN (TREE_VALUE (t));
  7953.                 if (t == NULL_TREE)
  7954.                   error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname));
  7955.                 t = build_tree_list (NULL_TREE, t);
  7956.                   }
  7957.                 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
  7958.                 DECL_INITIAL (t) = init;
  7959.                 return t;
  7960.               }
  7961.  
  7962.             if (flags == TYPENAME_FLAG)
  7963.               error_with_aggr_type (ctype, "type conversion is not a member of structure `%s'");
  7964.             else
  7965.               error ("field `%s' is not a member of structure `%s'",
  7966.                  IDENTIFIER_POINTER (sname),
  7967.                  TYPE_NAME_STRING (ctype));
  7968.               }
  7969.             if (TREE_CODE (type) == FUNCTION_TYPE)
  7970.               type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  7971.                               TREE_TYPE (type), TYPE_ARG_TYPES (type));
  7972.             else
  7973.               {
  7974.             if (current_class_type)
  7975.               {
  7976.                 if (TYPE_MAIN_VARIANT (ctype) != current_class_type)
  7977.                   {
  7978.                 error ("cannot declare member `%s::%s' within this class",
  7979.                        TYPE_NAME_STRING (ctype), name);
  7980.                   return void_type_node;
  7981.                   }
  7982.                 else if (extra_warnings)
  7983.                   warning ("extra qualification `%s' on member `%s' ignored",
  7984.                        TYPE_NAME_STRING (ctype), name);
  7985.               }
  7986.             type = build_offset_type (ctype, type);
  7987.               }
  7988.           }
  7989.         else if (uses_template_parms (ctype))
  7990.           {
  7991.                     enum tree_code c;
  7992.                     if (TREE_CODE (type) == FUNCTION_TYPE)
  7993.               {
  7994.             type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  7995.                             TREE_TYPE (type),
  7996.                             TYPE_ARG_TYPES (type));
  7997.             c = FUNCTION_DECL;
  7998.               }
  7999.             }
  8000.         else
  8001.           sorry ("structure `%s' not yet defined",
  8002.              TYPE_NAME_STRING (ctype));
  8003.         declarator = sname;
  8004.           }
  8005.         else if (TREE_CODE (sname) == TYPE_EXPR)
  8006.           {
  8007.         /* A TYPE_EXPR will change types out from under us.
  8008.            So do the TYPE_EXPR now, and make this SCOPE_REF
  8009.            inner to the TYPE_EXPR's CALL_EXPR.
  8010.  
  8011.            This does not work if we don't get a CALL_EXPR back.
  8012.            I did not think about error recovery, hence the
  8013.            my_friendly_assert (0).  */
  8014.  
  8015.         /* Get the CALL_EXPR.  */
  8016.         sname = grokoptypename (sname, 0);
  8017.         my_friendly_assert (TREE_CODE (sname) == CALL_EXPR, 157);
  8018.         type = TREE_TYPE (TREE_OPERAND (sname, 0));
  8019.         /* Scope the CALL_EXPR's name.  */
  8020.         TREE_OPERAND (declarator, 1) = TREE_OPERAND (sname, 0);
  8021.         /* Put the SCOPE_EXPR in the CALL_EXPR's innermost position.  */
  8022.         TREE_OPERAND (sname, 0) = declarator;
  8023.         /* Now work from the CALL_EXPR.  */
  8024.         declarator = sname;
  8025.         continue;
  8026.           }
  8027.         else if (TREE_CODE (sname) == SCOPE_REF)
  8028.           my_friendly_abort (17);
  8029.         else
  8030.           {
  8031.           done_scoping:
  8032.         declarator = TREE_OPERAND (declarator, 1);
  8033.         if (declarator && TREE_CODE (declarator) == CALL_EXPR)
  8034.           /* In this case, we will deal with it later.  */
  8035.           ;
  8036.         else
  8037.           {
  8038.             if (TREE_CODE (type) == FUNCTION_TYPE)
  8039.               type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
  8040.             else
  8041.               type = build_offset_type (ctype, type);
  8042.           }
  8043.           }
  8044.       }
  8045.       break;
  8046.  
  8047.     case BIT_NOT_EXPR:
  8048.       declarator = TREE_OPERAND (declarator, 0);
  8049.       break;
  8050.  
  8051.     case TYPE_EXPR:
  8052.       declarator = grokoptypename (declarator, 0);
  8053.       if (explicit_int != -1)
  8054.         if (comp_target_types (type, TREE_TYPE (TREE_OPERAND (declarator, 0)), 1) == 0)
  8055.           error ("type conversion function declared to return incongruent type");
  8056.         else
  8057.           pedwarn ("return type specified for type conversion function");
  8058.       type = TREE_TYPE (TREE_OPERAND (declarator, 0));
  8059.       maybe_globalize_type (type);
  8060.       break;
  8061.  
  8062.     case RECORD_TYPE:
  8063.     case UNION_TYPE:
  8064.     case ENUMERAL_TYPE:
  8065.       declarator = 0;
  8066.       break;
  8067.  
  8068.     case ERROR_MARK:
  8069.       declarator = 0;
  8070.       break;
  8071.  
  8072.     default:
  8073.       my_friendly_assert (0, 158);
  8074.     }
  8075.     }
  8076.  
  8077.   /* Now TYPE has the actual type.  */
  8078.  
  8079.   /* If this is declaring a typedef name, return a TYPE_DECL.  */
  8080.  
  8081.   if (specbits & (1 << (int) RID_TYPEDEF))
  8082.     {
  8083.       tree decl;
  8084.  
  8085.       /* Note that the grammar rejects storage classes
  8086.      in typenames, fields or parameters.  */
  8087.       if (constp || volatilep)
  8088.     type = build_type_variant (type, constp, volatilep);
  8089.  
  8090.       /* If the user declares "struct {...} foo" then `foo' will have
  8091.      an anonymous name.  Fill that name in now.  Nothing can
  8092.      refer to it, so nothing needs know about the name change.
  8093.      The TYPE_NAME field was filled in by build_struct_xref.  */
  8094.       if (TYPE_NAME (type)
  8095.       && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  8096.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
  8097.     {
  8098.       /* replace the anonymous name with the real name everywhere.  */
  8099.       lookup_tag_reverse (type, declarator);
  8100.       TYPE_IDENTIFIER (type) = declarator;
  8101.     }
  8102.  
  8103. #if 0 /* not yet, should get fixed properly later */
  8104.       decl = make_type_decl (declarator, type);
  8105. #else
  8106.       decl = build_decl (TYPE_DECL, declarator, type);
  8107. #endif
  8108.       if (quals)
  8109.     {
  8110.       if (ctype == NULL_TREE)
  8111.         {
  8112.           if (TREE_CODE (type) != METHOD_TYPE)
  8113.         error_with_decl (decl, "invalid type qualifier for non-method type");
  8114.           else
  8115.         ctype = TYPE_METHOD_BASETYPE (type);
  8116.         }
  8117.       if (ctype != NULL_TREE)
  8118.         grok_method_quals (ctype, decl, quals);
  8119.     }
  8120.  
  8121.       if ((specbits & (1 << (int) RID_SIGNED))
  8122.       || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
  8123.     C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
  8124.  
  8125.       return decl;
  8126.     }
  8127.  
  8128.   /* Detect the case of an array type of unspecified size
  8129.      which came, as such, direct from a typedef name.
  8130.      We must copy the type, so that each identifier gets
  8131.      a distinct type, so that each identifier's size can be
  8132.      controlled separately by its own initializer.  */
  8133.  
  8134.   if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
  8135.       && TYPE_DOMAIN (type) == 0)
  8136.     {
  8137.       type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
  8138.     }
  8139.  
  8140.   /* If this is a type name (such as, in a cast or sizeof),
  8141.      compute the type and return it now.  */
  8142.  
  8143.   if (decl_context == TYPENAME)
  8144.     {
  8145.       /* Note that the grammar rejects storage classes
  8146.      in typenames, fields or parameters.  */
  8147.       if (constp || volatilep)
  8148.     type = build_type_variant (type, constp, volatilep);
  8149.  
  8150.       /* Special case: "friend class foo" looks like a TYPENAME context.  */
  8151.       if (friendp)
  8152.     {
  8153.       /* A friendly class?  */
  8154.       if (current_class_type)
  8155.         make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
  8156.       else
  8157.         error("trying to make class `%s' a friend of global scope",
  8158.           TYPE_NAME_STRING (type));
  8159.       type = void_type_node;
  8160.     }
  8161.       else if (quals)
  8162.     {
  8163. #if 0 /* not yet, should get fixed properly later */
  8164.       tree dummy = make_type_decl (declarator, type);
  8165. #else
  8166.       tree dummy = build_decl (TYPE_DECL, declarator, type);
  8167. #endif
  8168.       if (ctype == NULL_TREE)
  8169.         {
  8170.           my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159);
  8171.           ctype = TYPE_METHOD_BASETYPE (type);
  8172.         }
  8173.       grok_method_quals (ctype, dummy, quals);
  8174.       type = TREE_TYPE (dummy);
  8175.     }
  8176.  
  8177.       return type;
  8178.     }
  8179.  
  8180.   /* `void' at top level (not within pointer)
  8181.      is allowed only in typedefs or type names.
  8182.      We don't complain about parms either, but that is because
  8183.      a better error message can be made later.  */
  8184.  
  8185.   if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
  8186.     {
  8187.       if (declarator != NULL_TREE
  8188.       && TREE_CODE (declarator) == IDENTIFIER_NODE)
  8189.     error ("variable or field `%s' declared void", name);
  8190.       else
  8191.     error ("variable or field declared void");
  8192.       type = integer_type_node;
  8193.     }
  8194.  
  8195.   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
  8196.      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
  8197.  
  8198.   {
  8199.     register tree decl;
  8200.  
  8201.     if (decl_context == PARM)
  8202.       {
  8203.     tree parmtype = type;
  8204.  
  8205.     if (ctype)
  8206.       error ("cannot use `::' in parameter declaration");
  8207.     if (virtualp)
  8208.       error ("parameter declared `virtual'");
  8209.     if (quals)
  8210.       error ("`const' and `volatile' function specifiers invalid in parameter declaration");
  8211.     if (friendp)
  8212.       error ("invalid friend declaration");
  8213.     if (raises)
  8214.       error ("invalid raises declaration");
  8215.  
  8216.     /* A parameter declared as an array of T is really a pointer to T.
  8217.        One declared as a function is really a pointer to a function.
  8218.        One declared as a member is really a pointer to member.
  8219.  
  8220.        Don't be misled by references.  */
  8221.  
  8222.     if (TREE_CODE (type) == REFERENCE_TYPE)
  8223.       type = TREE_TYPE (type);
  8224.  
  8225.     if (TREE_CODE (type) == ARRAY_TYPE)
  8226.       {
  8227.         if (parmtype == type)
  8228.           {
  8229.         /* Transfer const-ness of array into that of type
  8230.            pointed to.  */
  8231.         type = build_pointer_type
  8232.           (build_type_variant (TREE_TYPE (type), constp, volatilep));
  8233.         volatilep = constp = 0;
  8234.           }
  8235.         else
  8236.           type = build_pointer_type (TREE_TYPE (type));
  8237.       }
  8238.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  8239.       type = build_pointer_type (type);
  8240.     else if (TREE_CODE (type) == OFFSET_TYPE)
  8241.       type = build_pointer_type (type);
  8242.  
  8243.     if (TREE_CODE (parmtype) == REFERENCE_TYPE)
  8244.       {
  8245.         /* Transfer const-ness of reference into that of type pointed to.  */
  8246.         type = build_type_variant (build_reference_type (type), constp, volatilep);
  8247.         constp = volatilep = 0;
  8248.       }
  8249.  
  8250.     decl = build_decl (PARM_DECL, declarator, type);
  8251.  
  8252.     /* Compute the type actually passed in the parmlist,
  8253.        for the case where there is no prototype.
  8254.        (For example, shorts and chars are passed as ints.)
  8255.        When there is a prototype, this is overridden later.  */
  8256.  
  8257.     DECL_ARG_TYPE (decl) = type;
  8258. #ifdef APPLE_HAX
  8259.     /* All float args always passed as long doubles */
  8260.     if (flag_apple && (TYPE_MAIN_VARIANT (type) == float_type_node ||
  8261.             TYPE_MAIN_VARIANT (type) == double_type_node))
  8262.       DECL_ARG_TYPE (decl) = long_double_type_node;
  8263.     else
  8264. #endif /* APPLE_HAX */
  8265.     if (TYPE_MAIN_VARIANT (type) == float_type_node)
  8266.       DECL_ARG_TYPE (decl) = build_type_variant (double_type_node,
  8267.                              TYPE_READONLY (type),
  8268.                              TYPE_VOLATILE (type));
  8269.     else if (C_PROMOTING_INTEGER_TYPE_P (type))
  8270.       {
  8271.         tree argtype;
  8272.  
  8273.         /* Retain unsignedness if traditional or if not really
  8274.            getting wider.  */
  8275.         if (TREE_UNSIGNED (type)
  8276.         && (flag_traditional
  8277.             || TYPE_PRECISION (type)
  8278.             == TYPE_PRECISION (integer_type_node)))
  8279.           argtype = unsigned_type_node;
  8280.         else
  8281.           argtype = integer_type_node;
  8282.         DECL_ARG_TYPE (decl) = build_type_variant (argtype,
  8283.                                TYPE_READONLY (type),
  8284.                                TYPE_VOLATILE (type));
  8285.       }
  8286.       }
  8287.     else if (decl_context == FIELD)
  8288.       {
  8289.     if (type == error_mark_node)
  8290.       {
  8291.         /* Happens when declaring arrays of sizes which
  8292.            are error_mark_node, for example.  */
  8293.         decl = NULL_TREE;
  8294.       }
  8295.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  8296.       {
  8297.         if (friendp == 0)
  8298.           {
  8299.         if (ctype == NULL_TREE)
  8300.           ctype = current_class_type;
  8301.  
  8302.         if (ctype == NULL_TREE)
  8303.           {
  8304.             register int op = IDENTIFIER_OPNAME_P (declarator);
  8305.             error ("can't make %s `%s' into a method -- not in a class",
  8306.                op ? "operator" : "function",
  8307.                op ? operator_name_string (declarator) : IDENTIFIER_POINTER (declarator));
  8308.             return void_type_node;
  8309.           }
  8310.  
  8311.         /* ``A union may [ ... ] not [ have ] virtual functions.''
  8312.            ARM 9.5 */
  8313.         if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
  8314.           {
  8315.             error ("function `%s' declared virtual inside a union",
  8316.                IDENTIFIER_POINTER (declarator));
  8317.             return void_type_node;
  8318.           }
  8319.  
  8320.         /* Don't convert type of operators new and delete to
  8321.            METHOD_TYPE; they remain FUNCTION_TYPEs.  */
  8322.         if (staticp < 2
  8323.             && declarator != ansi_opname[(int) NEW_EXPR]
  8324.             && declarator != ansi_opname[(int) DELETE_EXPR])
  8325.           type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  8326.                           TREE_TYPE (type), TYPE_ARG_TYPES (type));
  8327.           }
  8328.         decl = grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, friendp ? -1 : 0);
  8329.         DECL_INLINE (decl) = inlinep;
  8330.         if ((specbits & (1 << (int) RID_EXTERN))
  8331.         || (ctype != NULL_TREE && funcdef_flag >= 0)
  8332.         || (friendp
  8333.                     && !(specbits & (1 << (int) RID_STATIC))
  8334.                     && !(specbits & (1 << (int) RID_INLINE))))
  8335.           TREE_PUBLIC (decl) = 1;
  8336.       }
  8337.     else if (TREE_CODE (type) == METHOD_TYPE)
  8338.       {
  8339.         decl = grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, friendp ? -1 : 0);
  8340.         DECL_INLINE (decl) = inlinep;
  8341.         /* All method decls are public.  */
  8342.         TREE_PUBLIC (decl) = 1;
  8343.       }
  8344.     else if (TREE_CODE (type) == RECORD_TYPE
  8345.          && CLASSTYPE_DECLARED_EXCEPTION (type))
  8346.       {
  8347.         /* Handle a class-local exception declaration.  */
  8348.         decl = build_lang_field_decl (VAR_DECL, declarator, type);
  8349.         if (ctype == NULL_TREE)
  8350.           ctype = current_class_type;
  8351.         finish_exception_decl (TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
  8352.                    ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype), decl);
  8353.         return void_type_node;
  8354.       }
  8355.     else if (TYPE_SIZE (type) == 0 && !staticp
  8356.          && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
  8357.       {
  8358.         if (declarator)
  8359.           error ("field `%s' has incomplete type",
  8360.              IDENTIFIER_POINTER (declarator));
  8361.         else
  8362.           error ("field has incomplete type");
  8363.         type = error_mark_node;
  8364.         decl = NULL_TREE;
  8365.       }
  8366.     else
  8367.       {
  8368.         if (friendp)
  8369.           {
  8370.         if (declarator)
  8371.           error ("`%s' is neither function nor method; cannot be declared friend",
  8372.              IDENTIFIER_POINTER (declarator));
  8373.         else
  8374.           {
  8375.             error ("invalid friend declaration");
  8376.             return void_type_node;
  8377.           }
  8378.         friendp = 0;
  8379.           }
  8380.         decl = NULL_TREE;
  8381.       }
  8382.  
  8383.     if (friendp)
  8384.       {
  8385.         /* Friends are treated specially.  */
  8386.         if (ctype == current_class_type)
  8387.           warning ("member functions are implicitly friends of their class");
  8388.         else if (decl && DECL_NAME (decl))
  8389.           return do_friend (ctype, declarator, decl,
  8390.                 last_function_parms, flags, quals);
  8391.         else return void_type_node;
  8392.       }
  8393.  
  8394.     /* Structure field.  It may not be a function, except for C++ */
  8395.  
  8396.     if (decl == 0)
  8397.       {
  8398.         if (virtualp)
  8399.           error ("field declared `virtual'");
  8400.         if (quals)
  8401.           error ("`const' and `volatile' function specifiers invalid in field declaration");
  8402.         if (friendp)
  8403.           error ("invalid friend declaration");
  8404.         if (raises)
  8405.           error ("invalid raises declaration");
  8406.  
  8407.         /* ANSI C++ June 5 1992 WP 9.2.2 and 9.4.2.  A member-declarator
  8408.            cannot have an initializer, and a static member declaration must
  8409.            be defined elsewhere.  */
  8410.         if (initialized)
  8411.           {
  8412.         if (staticp)
  8413.           error ("static member `%s' must be defined separately from its declaration",
  8414.               IDENTIFIER_POINTER (declarator));
  8415.         /* Note that initialization of const members is not
  8416.            mentioned in the ARM or draft ANSI standard explicitly,
  8417.            and it appears to be in common practice.  However,
  8418.            reading the draft section 9.2.2, it does say that a
  8419.            member declarator can't have an initializer--it does
  8420.            not except constant members, which also qualify as
  8421.            member-declarators.  */
  8422.         else if (!constp || pedantic)
  8423.           error ("ANSI C++ forbids initialization of %s `%s'",
  8424.              (constp && pedantic) ? "const member" : "member",
  8425.              IDENTIFIER_POINTER (declarator));
  8426.           }
  8427.  
  8428.         if (staticp || (constp && initialized))
  8429.           {
  8430.         /* C++ allows static class members.
  8431.            All other work for this is done by grokfield.
  8432.            This VAR_DECL is built by build_lang_field_decl.
  8433.            All other VAR_DECLs are built by build_decl.  */
  8434.         decl = build_lang_field_decl (VAR_DECL, declarator, type);
  8435.         if (staticp || TREE_CODE (type) == ARRAY_TYPE)
  8436.           TREE_STATIC (decl) = 1;
  8437.         /* In class context, static means public visibility.  */
  8438.         TREE_PUBLIC (decl) = 1;
  8439.         DECL_EXTERNAL (decl) = !initialized;
  8440.           }
  8441.         else
  8442.           decl = build_lang_field_decl (FIELD_DECL, declarator, type);
  8443.       }
  8444.       }
  8445.     else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
  8446.       {
  8447.     int was_overloaded = 0;
  8448.     tree original_name = declarator;
  8449.  
  8450.     if (! declarator) return NULL_TREE;
  8451.  
  8452.     if (specbits & ((1 << (int) RID_AUTO) | (1 << (int) RID_REGISTER)))
  8453.       error ("invalid storage class for function `%s'", name);
  8454.     /* Function declaration not at top level.
  8455.        Storage classes other than `extern' are not allowed
  8456.        and `extern' makes no difference.  */
  8457.     if (current_binding_level != global_binding_level
  8458.         && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
  8459.         && pedantic)
  8460.       pedwarn ("invalid storage class for function `%s'", name);
  8461.  
  8462.     if (ctype == NULL_TREE)
  8463.       {
  8464.         if (virtualp)
  8465.           {
  8466.         error ("virtual non-class function `%s'", name);
  8467.         virtualp = 0;
  8468.           }
  8469.         if (current_lang_name == lang_name_cplusplus
  8470.         && ! (IDENTIFIER_LENGTH (original_name) == 4
  8471.               && IDENTIFIER_POINTER (original_name)[0] == 'm'
  8472.               && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
  8473.         && ! (IDENTIFIER_LENGTH (original_name) > 10
  8474.               && IDENTIFIER_POINTER (original_name)[0] == '_'
  8475.               && IDENTIFIER_POINTER (original_name)[1] == '_'
  8476.               && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
  8477.           {
  8478.         /* Plain overloading: will not be grok'd by grokclassfn.  */
  8479.         declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
  8480.         was_overloaded = 1;
  8481.           }
  8482.       }
  8483.     else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
  8484.       type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  8485.                       TREE_TYPE (type), TYPE_ARG_TYPES (type));
  8486.     decl = grokfndecl (ctype, type, original_name, virtualp, flags, quals,
  8487.                raises,
  8488.                processing_template_decl ? 0 : friendp ? 2 : 1);
  8489.     if (ctype == NULL_TREE)
  8490.       DECL_ASSEMBLER_NAME (decl) = declarator;
  8491.     if (staticp == 1)
  8492.       {
  8493.         int illegal_static = 0;
  8494.  
  8495.         /* Don't allow a static member function in a class, and forbid declaring
  8496.            main to be static.  */
  8497.         if (TREE_CODE (type) == METHOD_TYPE)
  8498.           {
  8499.         error_with_decl (decl,
  8500.                  "cannot declare member function `%s' to have static linkage");
  8501.         illegal_static = 1;
  8502.           }
  8503.         else if (! was_overloaded
  8504.              && ! ctype
  8505.              && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
  8506.           {
  8507.         error ("cannot declare function `main' to have static linkage");
  8508.         illegal_static = 1;
  8509.           }
  8510.  
  8511.         if (illegal_static)
  8512.           {
  8513.         staticp = 0;
  8514.         specbits &= ~(1 << (int)RID_STATIC);
  8515.           }
  8516.       }
  8517.  
  8518.     /* Record presence of `static'.  In C++, `inline' is like `static'.
  8519.        Methods of classes should be public, unless we're dropping them
  8520.        into some other file, so we don't clear TREE_PUBLIC for them.  */
  8521.     TREE_PUBLIC (decl)
  8522.       = ((ctype
  8523.           && ! CLASSTYPE_INTERFACE_UNKNOWN (ctype)
  8524.           && ! CLASSTYPE_INTERFACE_ONLY (ctype))
  8525.         || !(specbits & ((1 << (int) RID_STATIC)
  8526.                  | (1 << (int) RID_INLINE))));
  8527.     /* Record presence of `inline', if it is reasonable.  */
  8528.     if (inlinep)
  8529.       {
  8530.         tree last = tree_last (TYPE_ARG_TYPES (type));
  8531.  
  8532.         if (! was_overloaded
  8533.         && ! ctype
  8534.         && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
  8535.           warning ("cannot inline function `main'");
  8536.         else if (last && last != void_list_node)
  8537.           warning ("inline declaration ignored for function with `...'");
  8538.         else
  8539.           /* Assume that otherwise the function can be inlined.  */
  8540.           DECL_INLINE (decl) = 1;
  8541.  
  8542.         if (specbits & (1 << (int) RID_EXTERN))
  8543.           {
  8544.         current_extern_inline = 1;
  8545.         if (pedantic)
  8546.           error ("ANSI C++ does not permit `extern inline'");
  8547.         else if (flag_ansi)
  8548.           warning ("ANSI C++ does not permit `extern inline'");
  8549.           }
  8550.       }
  8551.     if (was_overloaded)
  8552.       DECL_OVERLOADED (decl) = 1;
  8553. #ifdef APPLE_HAX
  8554.     /* If we saw a `pascal' keyword, set a bit in the tree node. */
  8555.     if (pascalp)
  8556.       TREE_PASCAL (decl) = 1;
  8557. #endif /* APPLE_HAX */
  8558.       }
  8559.     else
  8560.       {
  8561.     /* It's a variable.  */
  8562.  
  8563.     if (virtualp)
  8564.       error ("variable declared `virtual'");
  8565.     if (inlinep)
  8566.       warning ("variable declared `inline'");
  8567.     if (quals)
  8568.       error ("`const' and `volatile' function specifiers invalid in field declaration");
  8569.     if (friendp)
  8570.       error ("invalid friend declaration");
  8571.     if (raises)
  8572.       error ("invalid raises declaration");
  8573.  
  8574.     /* An uninitialized decl with `extern' is a reference.  */
  8575.     decl = grokvardecl (ctype, type, declarator, specbits, initialized);
  8576. #ifdef APPLE_HAX
  8577.     /* If we saw a `pascal' keyword, set a bit in the tree node. */
  8578.     if (pascalp)
  8579.       TREE_PASCAL (decl) = 1;
  8580. #endif /* APPLE_HAX */
  8581.     if (ctype)
  8582.       {
  8583.         if (staticp == 1)
  8584.           {
  8585.             error ("cannot declare member `%s' to have static linkage",
  8586.                lang_printable_name (decl));
  8587.             staticp = 0;
  8588.             specbits &= ~(1 << (int)RID_STATIC);
  8589.           }
  8590.         if (specbits & 1 << (int) RID_EXTERN)
  8591.           {
  8592.             error ("cannot explicitly declare member `%s' to have extern linkage",
  8593.                lang_printable_name (decl));
  8594.             specbits &= ~(1 << (int)RID_EXTERN);
  8595.           }
  8596.       }
  8597.       }
  8598.  
  8599.     /* Record `register' declaration for warnings on &
  8600.        and in case doing stupid register allocation.  */
  8601.  
  8602.     if (specbits & (1 << (int) RID_REGISTER))
  8603.       DECL_REGISTER (decl) = 1;
  8604.  
  8605.     /* Record constancy and volatility.  */
  8606.  
  8607.     if (constp)
  8608.       TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
  8609. #ifdef APPLE_HAX
  8610.     if (volatilep || (flag_force_volatile && TREE_CODE (type) != FUNCTION_TYPE))
  8611. #else
  8612.     if (volatilep)
  8613. #endif
  8614.       {
  8615.     TREE_SIDE_EFFECTS (decl) = 1;
  8616.     TREE_THIS_VOLATILE (decl) = 1;
  8617.       }
  8618.  
  8619.     return decl;
  8620.   }
  8621. }
  8622.  
  8623. /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
  8624.    An empty exprlist is a parmlist.  An exprlist which
  8625.    contains only identifiers at the global level
  8626.    is a parmlist.  Otherwise, it is an exprlist.  */
  8627. int
  8628. parmlist_is_exprlist (exprs)
  8629.      tree exprs;
  8630. {
  8631.   if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
  8632.     return 0;
  8633.  
  8634.   if (current_binding_level == global_binding_level)
  8635.     {
  8636.       /* At the global level, if these are all identifiers,
  8637.      then it is a parmlist.  */
  8638.       while (exprs)
  8639.     {
  8640.       if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
  8641.         return 1;
  8642.       exprs = TREE_CHAIN (exprs);
  8643.     }
  8644.       return 0;
  8645.     }
  8646.   return 1;
  8647. }
  8648.  
  8649. /* Make sure that the this list of PARMS has a chance of being
  8650.    grokked by `grokparms'.
  8651.  
  8652.    @@ This is really weak, but the grammar does not allow us
  8653.    @@ to easily reject things that this has to catch as syntax errors.  */
  8654. static int
  8655. parmlist_is_random (parms)
  8656.      tree parms;
  8657. {
  8658.   if (parms == NULL_TREE)
  8659.     return 0;
  8660.  
  8661.   if (TREE_CODE (parms) != TREE_LIST)
  8662.     return 1;
  8663.  
  8664.   while (parms)
  8665.     {
  8666.       if (parms == void_list_node)
  8667.     return 0;
  8668.  
  8669.       if (TREE_CODE (TREE_VALUE (parms)) != TREE_LIST)
  8670.     return 1;
  8671.       /* Don't get faked out by overloaded functions, which
  8672.      masquerade as TREE_LISTs!  */
  8673.       if (TREE_TYPE (TREE_VALUE (parms)) == unknown_type_node)
  8674.     return 1;
  8675.       parms = TREE_CHAIN (parms);
  8676.     }
  8677.   return 0;
  8678. }
  8679.  
  8680. /* Subroutine of `grokparms'.  In a fcn definition, arg types must
  8681.    be complete.
  8682.  
  8683.    C++: also subroutine of `start_function'.  */
  8684. static void
  8685. require_complete_types_for_parms (parms)
  8686.      tree parms;
  8687. {
  8688.   while (parms)
  8689.     {
  8690.       tree type = TREE_TYPE (parms);
  8691.       if (TYPE_SIZE (type) == 0)
  8692.     {
  8693.       if (DECL_NAME (parms))
  8694.         error ("parameter `%s' has incomplete type",
  8695.            IDENTIFIER_POINTER (DECL_NAME (parms)));
  8696.       else
  8697.         error ("parameter has incomplete type");
  8698.       TREE_TYPE (parms) = error_mark_node;
  8699.     }
  8700. #if 0
  8701.       /* If the arg types are incomplete in a declaration,
  8702.      they must include undefined tags.
  8703.      These tags can never be defined in the scope of the declaration,
  8704.      so the types can never be completed,
  8705.      and no call can be compiled successfully.  */
  8706.       /* This is not the right behavior for C++, but not having
  8707.      it is also probably wrong.  */
  8708.       else
  8709.     {
  8710.       /* Now warn if is a pointer to an incomplete type.  */
  8711.       while (TREE_CODE (type) == POINTER_TYPE
  8712.          || TREE_CODE (type) == REFERENCE_TYPE)
  8713.         type = TREE_TYPE (type);
  8714.       type = TYPE_MAIN_VARIANT (type);
  8715.       if (TYPE_SIZE (type) == 0)
  8716.         {
  8717.           if (DECL_NAME (parm) != 0)
  8718.         warning ("parameter `%s' points to incomplete type",
  8719.              IDENTIFIER_POINTER (DECL_NAME (parm)));
  8720.           else
  8721.         warning ("parameter points to incomplete type");
  8722.         }
  8723.     }
  8724. #endif
  8725.       parms = TREE_CHAIN (parms);
  8726.     }
  8727. }
  8728.  
  8729. /* Decode the list of parameter types for a function type.
  8730.    Given the list of things declared inside the parens,
  8731.    return a list of types.
  8732.  
  8733.    The list we receive can have three kinds of elements:
  8734.    an IDENTIFIER_NODE for names given without types,
  8735.    a TREE_LIST node for arguments given as typespecs or names with typespecs,
  8736.    or void_type_node, to mark the end of an argument list
  8737.    when additional arguments are not permitted (... was not used).
  8738.  
  8739.    FUNCDEF_FLAG is nonzero for a function definition, 0 for
  8740.    a mere declaration.  A nonempty identifier-list gets an error message
  8741.    when FUNCDEF_FLAG is zero.
  8742.    If FUNCDEF_FLAG is 1, then parameter types must be complete.
  8743.    If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
  8744.  
  8745.    If all elements of the input list contain types,
  8746.    we return a list of the types.
  8747.    If all elements contain no type (except perhaps a void_type_node
  8748.    at the end), we return a null list.
  8749.    If some have types and some do not, it is an error, and we
  8750.    return a null list.
  8751.  
  8752.    Also set last_function_parms to either
  8753.    a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
  8754.    A list of names is converted to a chain of PARM_DECLs
  8755.    by store_parm_decls so that ultimately it is always a chain of decls.
  8756.  
  8757.    Note that in C++, parameters can take default values.  These default
  8758.    values are in the TREE_PURPOSE field of the TREE_LIST.  It is
  8759.    an error to specify default values which are followed by parameters
  8760.    that have no default values, or an ELLIPSES.  For simplicities sake,
  8761.    only parameters which are specified with their types can take on
  8762.    default values.  */
  8763.  
  8764. static tree
  8765. grokparms (first_parm, funcdef_flag)
  8766.      tree first_parm;
  8767.      int funcdef_flag;
  8768. {
  8769.   tree result = NULL_TREE;
  8770.   tree decls = NULL_TREE;
  8771.  
  8772.   if (first_parm != 0
  8773.       && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
  8774.     {
  8775.       if (! funcdef_flag)
  8776.     warning ("parameter names (without types) in function declaration");
  8777.       last_function_parms = first_parm;
  8778.       return 0;
  8779.     }
  8780.   else
  8781.     {
  8782.       /* Types were specified.  This is a list of declarators
  8783.      each represented as a TREE_LIST node.  */
  8784.       register tree parm, chain;
  8785.       int any_init = 0, any_error = 0, saw_void = 0;
  8786.  
  8787.       if (first_parm != NULL_TREE)
  8788.     {
  8789.       tree last_result = NULL_TREE;
  8790.       tree last_decl = NULL_TREE;
  8791.  
  8792.       for (parm = first_parm; parm != NULL_TREE; parm = chain)
  8793.         {
  8794.           tree type, list_node = parm;
  8795.           register tree decl = TREE_VALUE (parm);
  8796.           tree init = TREE_PURPOSE (parm);
  8797.  
  8798.           chain = TREE_CHAIN (parm);
  8799.           /* @@ weak defense against parse errors.  */
  8800.           if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
  8801.         {
  8802.           /* Give various messages as the need arises.  */
  8803.           if (TREE_CODE (decl) == STRING_CST)
  8804.             error ("invalid string constant `%s'",
  8805.                TREE_STRING_POINTER (decl));
  8806.           else if (TREE_CODE (decl) == INTEGER_CST)
  8807.             error ("invalid integer constant in parameter list, did you forget to give parameter name?");
  8808.           continue;
  8809.         }
  8810.  
  8811.           if (decl != void_type_node)
  8812.         {
  8813.           /* @@ May need to fetch out a `raises' here.  */
  8814.           decl = grokdeclarator (TREE_VALUE (decl),
  8815.                      TREE_PURPOSE (decl),
  8816.                      PARM, init != NULL_TREE, NULL_TREE);
  8817.           if (! decl)
  8818.             continue;
  8819.           type = TREE_TYPE (decl);
  8820.           if (TYPE_MAIN_VARIANT (type) == void_type_node)
  8821.             decl = void_type_node;
  8822.           else if (TREE_CODE (type) == METHOD_TYPE)
  8823.             {
  8824.               if (DECL_NAME (decl))
  8825.             /* Cannot use `error_with_decl' here because
  8826.                we don't have DECL_CONTEXT set up yet.  */
  8827.             error ("parameter `%s' invalidly declared method type",
  8828.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  8829.               else
  8830.             error ("parameter invalidly declared method type");
  8831.               type = build_pointer_type (type);
  8832.               TREE_TYPE (decl) = type;
  8833.             }
  8834.           else if (TREE_CODE (type) == OFFSET_TYPE)
  8835.             {
  8836.               if (DECL_NAME (decl))
  8837.             error ("parameter `%s' invalidly declared offset type",
  8838.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  8839.               else
  8840.             error ("parameter invalidly declared offset type");
  8841.               type = build_pointer_type (type);
  8842.               TREE_TYPE (decl) = type;
  8843.             }
  8844.                   else if (TREE_CODE (type) == RECORD_TYPE
  8845.                            && TYPE_LANG_SPECIFIC (type)
  8846.                            && CLASSTYPE_ABSTRACT_VIRTUALS (type))
  8847.                     {
  8848.                       abstract_virtuals_error (decl, type);
  8849.                       any_error = 1;  /* seems like a good idea */
  8850.                     }
  8851.         }
  8852.  
  8853.           if (decl == void_type_node)
  8854.         {
  8855.           if (result == NULL_TREE)
  8856.             {
  8857.               result = void_list_node;
  8858.               last_result = result;
  8859.             }
  8860.           else
  8861.             {
  8862.               TREE_CHAIN (last_result) = void_list_node;
  8863.               last_result = void_list_node;
  8864.             }
  8865.           saw_void = 1;
  8866.           if (chain
  8867.               && (chain != void_list_node || TREE_CHAIN (chain)))
  8868.             error ("`void' in parameter list must be entire list");
  8869.           break;
  8870.         }
  8871.  
  8872.           /* Since there is a prototype, args are passed in their own types.  */
  8873.           DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
  8874. #ifdef PROMOTE_PROTOTYPES
  8875.           if (C_PROMOTING_INTEGER_TYPE_P (type))
  8876.         DECL_ARG_TYPE (decl) = integer_type_node;
  8877. #endif
  8878. #ifdef APPLE_HAX
  8879.     /* Promote all floating parameters to long double. */
  8880.     if (flag_apple && TREE_CODE (type) == REAL_TYPE
  8881.         && TYPE_PRECISION (type) < TYPE_PRECISION (long_double_type_node))
  8882.       DECL_ARG_TYPE (decl) = long_double_type_node;
  8883. #endif /* APPLE_HAX */
  8884.           if (!any_error)
  8885.         {
  8886.           if (init)
  8887.             {
  8888.               any_init++;
  8889.               if (TREE_CODE (init) == SAVE_EXPR)
  8890.             PARM_DECL_EXPR (init) = 1;
  8891.               else if (TREE_CODE (init) == VAR_DECL)
  8892.             {
  8893.               if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init)))
  8894.                 {
  8895.                   /* ``Local variables may not be used in default
  8896.                  argument expressions.'' dpANSI C++ 8.2.6 */
  8897.                   /* If extern int i; within a function is not
  8898.                  considered a local variable, then this code is
  8899.                  wrong. */
  8900.                   error_with_decl (init, "local variable `%s' may not be used as a default argument");
  8901.                   any_error = 1;
  8902.                 }
  8903.               else if (TREE_READONLY_DECL_P (init))
  8904.                 init = decl_constant_value (init);
  8905.             }
  8906.               else
  8907.             init = require_instantiated_type (type, init, integer_zero_node);
  8908.             }
  8909.           else if (any_init)
  8910.             {
  8911.               error ("all trailing parameters must have default arguments");
  8912.               any_error = 1;
  8913.             }
  8914.         }
  8915.           else
  8916.         init = NULL_TREE;
  8917.  
  8918.           if (decls == NULL_TREE)
  8919.         {
  8920.           decls = decl;
  8921.           last_decl = decls;
  8922.         }
  8923.           else
  8924.         {
  8925.           TREE_CHAIN (last_decl) = decl;
  8926.           last_decl = decl;
  8927.         }
  8928.           if (TREE_PERMANENT (list_node))
  8929.         {
  8930.           TREE_PURPOSE (list_node) = init;
  8931.           TREE_VALUE (list_node) = type;
  8932.           TREE_CHAIN (list_node) = 0;
  8933.         }
  8934.           else
  8935.         list_node = saveable_tree_cons (init, type, NULL_TREE);
  8936.           if (result == NULL_TREE)
  8937.         {
  8938.           result = list_node;
  8939.           last_result = result;
  8940.         }
  8941.           else
  8942.         {
  8943.           TREE_CHAIN (last_result) = list_node;
  8944.           last_result = list_node;
  8945.         }
  8946.         }
  8947.       if (last_result)
  8948.         TREE_CHAIN (last_result) = NULL_TREE;
  8949.       /* If there are no parameters, and the function does not end
  8950.          with `...', then last_decl will be NULL_TREE.  */
  8951.       if (last_decl != NULL_TREE)
  8952.         TREE_CHAIN (last_decl) = NULL_TREE;
  8953.     }
  8954.     }
  8955.  
  8956.   last_function_parms = decls;
  8957.  
  8958.   /* In a fcn definition, arg types must be complete.  */
  8959.   if (funcdef_flag > 0)
  8960.     require_complete_types_for_parms (last_function_parms);
  8961.  
  8962.   return result;
  8963. }
  8964.  
  8965. /* These memoizing functions keep track of special properties which
  8966.    a class may have.  `grok_ctor_properties' notices whether a class
  8967.    has a constructor of the for X(X&), and also complains
  8968.    if the class has a constructor of the form X(X).
  8969.    `grok_op_properties' takes notice of the various forms of
  8970.    operator= which are defined, as well as what sorts of type conversion
  8971.    may apply.  Both functions take a FUNCTION_DECL as an argument.  */
  8972. void
  8973. grok_ctor_properties (ctype, decl)
  8974.      tree ctype, decl;
  8975. {
  8976.   tree parmtypes = FUNCTION_ARG_CHAIN (decl);
  8977.   tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
  8978.  
  8979.   if (parmtypes && TREE_CHAIN (parmtypes)
  8980.       && TREE_CODE (TREE_VALUE (TREE_CHAIN (parmtypes))) == REFERENCE_TYPE
  8981.       && TYPE_USES_VIRTUAL_BASECLASSES (TREE_TYPE (TREE_VALUE (TREE_CHAIN (parmtypes)))))
  8982.     {
  8983.       parmtypes = TREE_CHAIN (parmtypes);
  8984.       parmtype = TREE_VALUE (parmtypes);
  8985.     }
  8986.  
  8987.   if (TREE_CODE (parmtype) == REFERENCE_TYPE
  8988.       && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
  8989.     {
  8990.       if (TREE_CHAIN (parmtypes) == NULL_TREE
  8991.       || TREE_CHAIN (parmtypes) == void_list_node
  8992.       || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
  8993.     {
  8994.       TYPE_HAS_INIT_REF (ctype) = 1;
  8995.       TYPE_GETS_INIT_REF (ctype) = 1;
  8996.       if (TYPE_READONLY (TREE_TYPE (parmtype)))
  8997.         TYPE_GETS_CONST_INIT_REF (ctype) = 1;
  8998.     }
  8999.       else
  9000.     TYPE_GETS_INIT_AGGR (ctype) = 1;
  9001.     }
  9002.   else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
  9003.     {
  9004.       if (TREE_CHAIN (parmtypes) != NULL_TREE
  9005.       && TREE_CHAIN (parmtypes) == void_list_node)
  9006.     error ("invalid constructor; you probably meant `%s (%s&)'",
  9007.            TYPE_NAME_STRING (ctype),
  9008.            TYPE_NAME_STRING (ctype));
  9009.       SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
  9010.       TYPE_GETS_INIT_AGGR (ctype) = 1;
  9011.     }
  9012.   else if (TREE_CODE (parmtype) == VOID_TYPE
  9013.        || TREE_PURPOSE (parmtypes) != NULL_TREE)
  9014.     TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
  9015. }
  9016.  
  9017. static void
  9018. grok_op_properties (decl, virtualp)
  9019.      tree decl;
  9020.      int virtualp;
  9021. {
  9022.   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  9023.  
  9024.   if (DECL_STATIC_FUNCTION_P (decl))
  9025.     {
  9026.       if (DECL_NAME (decl) == ansi_opname[(int) NEW_EXPR])
  9027.     {
  9028.       if (virtualp)
  9029.         error ("`operator new' cannot be declared virtual");
  9030.  
  9031.       /* Take care of function decl if we had syntax errors.  */
  9032.       if (argtypes == NULL_TREE)
  9033.         TREE_TYPE (decl) =
  9034.           build_function_type (ptr_type_node,
  9035.                    hash_tree_chain (integer_type_node,
  9036.                             void_list_node));
  9037.       else
  9038.         decl = coerce_new_type (TREE_TYPE (current_class_name),
  9039.                     TREE_TYPE (decl));
  9040.     }
  9041.       else if (DECL_NAME (decl) == ansi_opname[(int) DELETE_EXPR])
  9042.     {
  9043.       if (virtualp)
  9044.         error ("`operator delete' cannot be declared virtual");
  9045.  
  9046.       if (argtypes == NULL_TREE)
  9047.         TREE_TYPE (decl) =
  9048.           build_function_type (void_type_node,
  9049.                    hash_tree_chain (ptr_type_node,
  9050.                             void_list_node));
  9051.       else
  9052.         decl = coerce_delete_type (TREE_TYPE (current_class_name),
  9053.                        TREE_TYPE (decl));
  9054.     }
  9055.       else
  9056.     error_with_decl (decl, "`%s' cannot be a static member function");
  9057.     }
  9058.   else if (DECL_NAME (decl) == ansi_opname[(int) MODIFY_EXPR])
  9059.     {
  9060.       tree parmtypes;
  9061.       tree parmtype;
  9062.  
  9063.       if (argtypes == NULL_TREE)
  9064.     {
  9065.       error_with_decl (decl, "too few arguments to `%s'");
  9066.       return;
  9067.     }
  9068.       parmtypes = TREE_CHAIN (argtypes);
  9069.       parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
  9070.  
  9071.       if (TREE_CODE (parmtype) == REFERENCE_TYPE
  9072.       && TREE_TYPE (parmtype) == current_class_type)
  9073.     {
  9074.       TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
  9075.       TYPE_GETS_ASSIGN_REF (current_class_type) = 1;
  9076.       if (TYPE_READONLY (TREE_TYPE (parmtype)))
  9077.         TYPE_GETS_CONST_INIT_REF (current_class_type) = 1;
  9078.     }
  9079.     }
  9080. }
  9081.  
  9082. /* Get the struct, enum or union (CODE says which) with tag NAME.
  9083.    Define the tag as a forward-reference if it is not defined.
  9084.  
  9085.    C++: If a class derivation is given, process it here, and report
  9086.    an error if multiple derivation declarations are not identical.
  9087.  
  9088.    If this is a definition, come in through xref_tag and only look in
  9089.    the current frame for the name (since C++ allows new names in any
  9090.    scope.)
  9091.  
  9092.    If we are compiling for SOS, then
  9093.      if CODE_TYPE_NODE is a TREE_LIST, then we have a dynamic class
  9094.      declaration.  The name associated with the class is the tree
  9095.      purpose, and the real CODE is in the tree value slot.  */
  9096. /* avoid rewriting all callers of xref_tag */
  9097. static int xref_next_defn = 0;
  9098.  
  9099. tree
  9100. xref_defn_tag (code_type_node, name, binfo)
  9101.      tree code_type_node;
  9102.      tree name, binfo;
  9103. {
  9104.   tree rv, ncp;
  9105.   xref_next_defn = 1;
  9106.  
  9107.   if (class_binding_level)
  9108.     {
  9109.       tree n1;
  9110.       char *buf;
  9111.       /* we need to build a new IDENTIFIER_NODE for name which nukes
  9112.        * the pieces... */
  9113.       n1 = IDENTIFIER_LOCAL_VALUE (current_class_name);
  9114.       if (n1)
  9115.     n1 = DECL_NAME (n1);
  9116.       else
  9117.     n1 = current_class_name;
  9118.       
  9119.       buf = (char *) alloca (4 + IDENTIFIER_LENGTH (n1)
  9120.                  + IDENTIFIER_LENGTH (name));
  9121.       
  9122.       sprintf (buf, "%s::%s", IDENTIFIER_POINTER (n1),
  9123.            IDENTIFIER_POINTER (name));
  9124.       ncp = get_identifier (buf);
  9125. #ifdef SPEW_DEBUG
  9126.       if (spew_debug)
  9127.     printf("*** %s ***\n", IDENTIFIER_POINTER (ncp));
  9128. #endif
  9129. #if 0
  9130.       IDENTIFIER_LOCAL_VALUE (name) =
  9131.     build_lang_decl (TYPE_DECL, ncp, NULL_TREE);
  9132. #endif
  9133.       rv = xref_tag (code_type_node, name, binfo);
  9134.       pushdecl_top_level (build_lang_decl (TYPE_DECL, ncp, rv));
  9135.     }
  9136.   else
  9137.     {
  9138.       rv = xref_tag (code_type_node, name, binfo);
  9139.     }
  9140.   xref_next_defn = 0;
  9141.   return rv;
  9142. }
  9143.  
  9144. #ifdef MPW
  9145. #pragma segment CPDECL03
  9146. #endif
  9147.  
  9148. tree
  9149. xref_tag (code_type_node, name, binfo)
  9150.      tree code_type_node;
  9151.      tree name, binfo;
  9152. {
  9153.   enum tag_types tag_code;
  9154.   enum tree_code code;
  9155.   int temp = 0;
  9156.   int i, len;
  9157.   register tree ref;
  9158.   struct binding_level *b
  9159.     = (class_binding_level ? class_binding_level : current_binding_level);
  9160. #ifdef SOS
  9161.   tree dynamic_name = error_mark_node;
  9162.   if (TREE_CODE (code_type_node) == TREE_LIST)
  9163.     {
  9164.       dynamic_name = TREE_PURPOSE (code_type_node);
  9165.       code_type_node = TREE_VALUE (code_type_node);
  9166.     }
  9167. #endif
  9168.  
  9169.   tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
  9170.   switch (tag_code)
  9171.     {
  9172.     case record_type:
  9173.     case class_type:
  9174.     case exception_type:
  9175.       code = RECORD_TYPE;
  9176.       len = list_length (binfo);
  9177.       break;
  9178.     case union_type:
  9179.       code = UNION_TYPE;
  9180.       if (binfo)
  9181.     {
  9182.       error ("derived union `%s' invalid", IDENTIFIER_POINTER (name));
  9183.       binfo = NULL_TREE;
  9184.     }
  9185.       len = 0;
  9186.       break;
  9187.     case enum_type:
  9188.       code = ENUMERAL_TYPE;
  9189.       break;
  9190.     default:
  9191.       my_friendly_abort (18);
  9192.     }
  9193.  
  9194.   /* If a cross reference is requested, look up the type
  9195.      already defined for this tag and return it.  */
  9196.   if (xref_next_defn)
  9197.     {
  9198.       /* If we know we are defining this tag, only look it up in this scope
  9199.        * and don't try to find it as a type. */
  9200.       xref_next_defn = 0;
  9201.       ref = lookup_tag (code, name, b, 1);
  9202.     }
  9203.   else
  9204.     {
  9205.       ref = lookup_tag (code, name, b, 0);
  9206.  
  9207.       if (! ref)
  9208.     {
  9209.       /* Try finding it as a type declaration.  If that wins, use it.  */
  9210.       ref = lookup_name (name, 1);
  9211.       if (ref && TREE_CODE (ref) == TYPE_DECL
  9212.           && TREE_CODE (TREE_TYPE (ref)) == code)
  9213.         ref = TREE_TYPE (ref);
  9214.       else
  9215.         ref = NULL_TREE;
  9216.     }
  9217.     }
  9218.  
  9219.   push_obstacks_nochange ();
  9220.  
  9221.   if (! ref)
  9222.     {
  9223.       /* If no such tag is yet defined, create a forward-reference node
  9224.      and record it as the "definition".
  9225.      When a real declaration of this type is found,
  9226.      the forward-reference will be altered into a real type.  */
  9227.  
  9228.       /* In C++, since these migrate into the global scope, we must
  9229.      build them on the permanent obstack.  */
  9230.  
  9231.       temp = allocation_temporary_p ();
  9232.       if (temp)
  9233.     end_temporary_allocation ();
  9234.  
  9235.       if (code == ENUMERAL_TYPE)
  9236.     {
  9237.       ref = make_node (ENUMERAL_TYPE);
  9238.  
  9239.       /* Give the type a default layout like unsigned int
  9240.          to avoid crashing if it does not get defined.  */
  9241.       TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
  9242.       TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
  9243.       TREE_UNSIGNED (ref) = 1;
  9244.       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
  9245.       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
  9246.       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
  9247.  
  9248.       /* Enable us to recognize when a type is created in class context.
  9249.          To do nested classes correctly, this should probably be cleared
  9250.          out when we leave this classes scope.  Currently this in only
  9251.          done in `start_enum'.  */
  9252.  
  9253.       pushtag (name, ref);
  9254.       if (flag_cadillac)
  9255.         cadillac_start_enum (ref);
  9256.     }
  9257.       else if (tag_code == exception_type)
  9258.     {
  9259.       ref = make_lang_type (code);
  9260.       /* Enable us to recognize when an exception type is created in
  9261.          class context.  To do nested classes correctly, this should
  9262.          probably be cleared out when we leave this class's scope.  */
  9263.       CLASSTYPE_DECLARED_EXCEPTION (ref) = 1;
  9264.       pushtag (name, ref);
  9265.       if (flag_cadillac)
  9266.         cadillac_start_struct (ref);
  9267.     }
  9268.       else
  9269.     {
  9270.       extern tree pending_vtables;
  9271.       struct binding_level *old_b = class_binding_level;
  9272.       int needs_writing;
  9273.  
  9274.       ref = make_lang_type (code);
  9275.  
  9276.       /* Record how to set the visibility of this class's
  9277.          virtual functions.  If write_virtuals == 2 or 3, then
  9278.          inline virtuals are ``extern inline''.  */
  9279.       switch (write_virtuals)
  9280.         {
  9281.         case 0:
  9282.         case 1:
  9283.           needs_writing = 1;
  9284.           break;
  9285.         case 2:
  9286.           needs_writing = !! value_member (name, pending_vtables);
  9287.           break;
  9288.         case 3:
  9289.           needs_writing
  9290.         = ! (CLASSTYPE_INTERFACE_ONLY (ref) || CLASSTYPE_INTERFACE_UNKNOWN (ref));
  9291.           break;
  9292.         default:
  9293.           needs_writing = 0;
  9294.         }
  9295.  
  9296.       CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = needs_writing;
  9297.  
  9298. #ifdef NONNESTED_CLASSES
  9299.       /* Class types don't nest the way enums do.  */
  9300.       class_binding_level = 0;
  9301. #endif
  9302.       pushtag (name, ref);
  9303.       class_binding_level = old_b;
  9304.  
  9305.       if (flag_cadillac)
  9306.         cadillac_start_struct (ref);
  9307.     }
  9308.     }
  9309.   else
  9310.     {
  9311.       if (IS_AGGR_TYPE_CODE (code))
  9312.     {
  9313.       if (IS_AGGR_TYPE (ref)
  9314.           && ((tag_code == exception_type)
  9315.           != (CLASSTYPE_DECLARED_EXCEPTION (ref) == 1)))
  9316.         {
  9317.           error ("type `%s' is both exception and aggregate type",
  9318.              IDENTIFIER_POINTER (name));
  9319.           CLASSTYPE_DECLARED_EXCEPTION (ref) = (tag_code == exception_type);
  9320.         }
  9321.     }
  9322.  
  9323.       /* If it no longer looks like a nested type, make sure it's
  9324.      in global scope.  */
  9325.       if (b == global_binding_level && !class_binding_level
  9326.       && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
  9327.     IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
  9328.  
  9329.       if (binfo)
  9330.     {
  9331.       tree tt1 = binfo;
  9332.       tree tt2 = TYPE_BINFO_BASETYPES (ref);
  9333.  
  9334.       if (TYPE_BINFO_BASETYPES (ref))
  9335.         for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1))
  9336.           if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i))))
  9337.         {
  9338.           error ("redeclaration of derivation chain of type `%s'",
  9339.              IDENTIFIER_POINTER (name));
  9340.           break;
  9341.         }
  9342.  
  9343.       if (tt1 == NULL_TREE)
  9344.         /* The user told us something we already knew.  */
  9345.         goto just_return;
  9346.  
  9347.       /* In C++, since these migrate into the global scope, we must
  9348.          build them on the permanent obstack.  */
  9349.       end_temporary_allocation ();
  9350.     }
  9351. #ifdef SOS
  9352.       else if (TREE_CODE (ref) != ENUMERAL_TYPE
  9353.            && (dynamic_name != error_mark_node) != TYPE_DYNAMIC (ref))
  9354.     error ("type `%s' declared both dynamic and non-dynamic",
  9355.            IDENTIFIER_POINTER (name));
  9356. #endif
  9357.     }
  9358.  
  9359.   if (binfo)
  9360.     {
  9361.       /* In the declaration `A : X, Y, ... Z' we mark all the types
  9362.      (A, X, Y, ..., Z) so we can check for duplicates.  */
  9363.       tree binfos;
  9364.  
  9365.       SET_CLASSTYPE_MARKED (ref);
  9366.       BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
  9367.  
  9368.       for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
  9369.     {
  9370.       /* The base of a derived struct is public.  */
  9371.       int via_public = (tag_code != class_type
  9372.                 || TREE_PURPOSE (binfo) == (tree)visibility_public
  9373.                 || TREE_PURPOSE (binfo) == (tree)visibility_public_virtual);
  9374.       int via_protected = TREE_PURPOSE (binfo) == (tree)visibility_protected;
  9375.       int via_virtual = (TREE_PURPOSE (binfo) == (tree)visibility_private_virtual
  9376.                  || TREE_PURPOSE (binfo) == (tree)visibility_public_virtual
  9377.                  || TREE_PURPOSE (binfo) == (tree)visibility_default_virtual);
  9378.       tree basetype = TREE_TYPE (TREE_VALUE (binfo));
  9379.       tree base_binfo;
  9380.  
  9381.       GNU_xref_hier (IDENTIFIER_POINTER (name),
  9382.              IDENTIFIER_POINTER (TREE_VALUE (binfo)),
  9383.              via_public, via_virtual, 0);
  9384.  
  9385.       if (basetype && TREE_CODE (basetype) == TYPE_DECL)
  9386.         basetype = TREE_TYPE (basetype);
  9387.       if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
  9388.         {
  9389.           error ("base type `%s' fails to be a struct or class type",
  9390.              IDENTIFIER_POINTER (TREE_VALUE (binfo)));
  9391.           continue;
  9392.         }
  9393. #if 0
  9394.       else if (TYPE_SIZE (basetype) == 0)
  9395.         {
  9396.           error_with_aggr_type (basetype, "base class `%s' has incomplete type");
  9397.           continue;
  9398.         }
  9399. #endif
  9400.       else
  9401.         {
  9402. #ifdef SOS
  9403.           if (dynamic_name == error_mark_node && TYPE_DYNAMIC (basetype))
  9404.         error_with_aggr_type (ref, "non-dynamic type `%s' cannot derive from dynamic type `%s'", TYPE_NAME_STRING (basetype));
  9405. #endif
  9406.           if (CLASSTYPE_MARKED (basetype))
  9407.         {
  9408.           if (basetype == ref)
  9409.             error_with_aggr_type (basetype, "recursive type `%s' undefined");
  9410.           else
  9411.             error_with_aggr_type (basetype, "duplicate base type `%s' invalid");
  9412.           continue;
  9413.         }
  9414.  
  9415.            /* Note that the BINFO records which describe individual
  9416.           inheritances are *not* shared in the lattice!  They
  9417.           cannot be shared because a given baseclass may be
  9418.           inherited with different `accessability' by different
  9419.           derived classes.  (Each BINFO record describing an
  9420.           individual inheritance contains flags which say what
  9421.           the `accessability' of that particular inheritance is.)  */
  9422.   
  9423.           base_binfo = make_binfo (integer_zero_node, basetype,
  9424.                   TYPE_BINFO_VTABLE (basetype),
  9425.                    TYPE_BINFO_VIRTUALS (basetype), 0);
  9426.  
  9427.           TREE_VEC_ELT (binfos, i) = base_binfo;
  9428.           TREE_VIA_PUBLIC (base_binfo) = via_public;
  9429.            TREE_VIA_PROTECTED (base_binfo) = via_protected;
  9430.           TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
  9431.  
  9432.           SET_CLASSTYPE_MARKED (basetype);
  9433. #if 0
  9434. /* XYZZY TEST VIRTUAL BASECLASSES */
  9435. if (CLASSTYPE_N_BASECLASSES (basetype) == 0
  9436.     && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
  9437.     && via_virtual == 0)
  9438.   {
  9439.     warning ("making type `%s' a virtual baseclass",
  9440.          TYPE_NAME_STRING (basetype));
  9441.     via_virtual = 1;
  9442.   }
  9443. #endif
  9444.           /* We are free to modify these bits because they are meaningless
  9445.          at top level, and BASETYPE is a top-level type.  */
  9446.           if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
  9447.         {
  9448.           TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
  9449.           TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
  9450.         }
  9451.  
  9452.           TYPE_GETS_ASSIGNMENT (ref) |= TYPE_GETS_ASSIGNMENT (basetype);
  9453.           TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
  9454.           TREE_GETS_NEW (ref) |= TREE_GETS_NEW (basetype);
  9455.           TREE_GETS_DELETE (ref) |= TREE_GETS_DELETE (basetype);
  9456.           CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
  9457.           i += 1;
  9458.         }
  9459.     }
  9460.       if (i)
  9461.     TREE_VEC_LENGTH (binfos) = i;
  9462.       else
  9463.     BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
  9464.  
  9465.       if (i > 1)
  9466.     TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
  9467.       else if (i == 1)
  9468.     TYPE_USES_MULTIPLE_INHERITANCE (ref)
  9469.       = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
  9470.       if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
  9471.     TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
  9472.  
  9473.       /* Unmark all the types.  */
  9474.       while (--i >= 0)
  9475.     CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
  9476.       CLEAR_CLASSTYPE_MARKED (ref);
  9477.     }
  9478.  
  9479.  just_return:
  9480.  
  9481. #ifdef SOS
  9482.   if (dynamic_name != error_mark_node)
  9483.     {
  9484.       if (temp == 0)
  9485.     temp = allocation_temporary_p ();
  9486.       if (temp)
  9487.     end_temporary_allocation ();
  9488.  
  9489.       if (dynamic_name)
  9490.     CLASSTYPE_DYNAMIC_FILENAME (ref) = combine_strings (dynamic_name);
  9491.       else
  9492.     CLASSTYPE_DYNAMIC_FILENAME (ref) = NULL_TREE;
  9493.       TYPE_DYNAMIC (ref) = 1;
  9494.       CLASSTYPE_TYPENAME_AS_STRING (ref) = combine_strings (build_string (IDENTIFIER_LENGTH (name), IDENTIFIER_POINTER (name)));
  9495.  
  9496.     }
  9497. #endif
  9498.  
  9499.   /* Until the type is defined, tentatively accept whatever
  9500.      structure tag the user hands us.  */
  9501.   if (TYPE_SIZE (ref) == NULL_TREE
  9502.       && ref != current_class_type
  9503.       /* Have to check this, in case we have contradictory tag info.  */
  9504.       && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
  9505.     {
  9506.       if (tag_code == class_type)
  9507.     CLASSTYPE_DECLARED_CLASS (ref) = 1;
  9508.       else if (tag_code == record_type)
  9509.     CLASSTYPE_DECLARED_CLASS (ref) = 0;
  9510.     }
  9511.  
  9512.   pop_obstacks ();
  9513.  
  9514.   return ref;
  9515. }
  9516.  
  9517. /* Begin compiling the definition of an enumeration type.
  9518.    NAME is its name (or null if anonymous).
  9519.    Returns the type object, as yet incomplete.
  9520.    Also records info about it so that build_enumerator
  9521.    may be used to declare the individual values as they are read.  */
  9522.  
  9523. tree
  9524. start_enum (name)
  9525.      tree name;
  9526. {
  9527.   register tree enumtype = 0;
  9528.   struct binding_level *b
  9529.     = (class_binding_level ? class_binding_level : current_binding_level);
  9530.  
  9531.   /* If this is the real definition for a previous forward reference,
  9532.      fill in the contents in the same object that used to be the
  9533.      forward reference.  */
  9534.  
  9535.   if (name != 0)
  9536.     enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
  9537.  
  9538.   if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
  9539.     {
  9540.       enumtype = make_node (ENUMERAL_TYPE);
  9541.       pushtag (name, enumtype);
  9542.     }
  9543.  
  9544.   if (TYPE_VALUES (enumtype) != 0)
  9545.     {
  9546.       /* This enum is a named one that has been declared already.  */
  9547.       error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
  9548.  
  9549.       /* Completely replace its old definition.
  9550.      The old enumerators remain defined, however.  */
  9551.       TYPE_VALUES (enumtype) = 0;
  9552.     }
  9553.  
  9554.   /* Initially, set up this enum as like `int'
  9555.      so that we can create the enumerators' declarations and values.
  9556.      Later on, the precision of the type may be changed and
  9557.      it may be laid out again.  */
  9558.  
  9559.   TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
  9560.   TYPE_SIZE (enumtype) = 0;
  9561.   fixup_unsigned_type (enumtype);
  9562.  
  9563.   /* We copy this value because enumerated type constants
  9564.      are really of the type of the enumerator, not integer_type_node.  */
  9565.   enum_next_value = copy_node (integer_zero_node);
  9566.  
  9567.   GNU_xref_decl (current_function_decl, enumtype);
  9568.   return enumtype;
  9569. }
  9570.  
  9571. /* After processing and defining all the values of an enumeration type,
  9572.    install their decls in the enumeration type and finish it off.
  9573.    ENUMTYPE is the type object and VALUES a list of name-value pairs.
  9574.    Returns ENUMTYPE.  */
  9575.  
  9576. tree
  9577. finish_enum (enumtype, values)
  9578.      register tree enumtype, values;
  9579. {
  9580.   register tree pair;
  9581.   register HOST_WIDE_INT maxvalue = 0;
  9582.   register HOST_WIDE_INT minvalue = 0;
  9583.   register HOST_WIDE_INT i;
  9584.  
  9585.   TYPE_VALUES (enumtype) = values;
  9586.  
  9587.   /* Calculate the maximum value of any enumerator in this type.  */
  9588.  
  9589.   if (values)
  9590.     {
  9591.       /* Speed up the main loop by performing some precalculations */
  9592.  
  9593.       HOST_WIDE_INT value = TREE_INT_CST_LOW (TREE_VALUE (values));
  9594.       TREE_TYPE (TREE_VALUE (values)) = enumtype;
  9595.       minvalue = maxvalue = value;
  9596.       
  9597.       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
  9598.     {
  9599.       value = TREE_INT_CST_LOW (TREE_VALUE (pair));
  9600.       if (value > maxvalue)
  9601.         maxvalue = value;
  9602.       else if (value < minvalue)
  9603.         minvalue = value;
  9604.       TREE_TYPE (TREE_VALUE (pair)) = enumtype;
  9605.     }
  9606.     }
  9607.  
  9608.   if (flag_short_enums)
  9609.     {
  9610.       /* Determine the precision this type needs, lay it out, and define it.  */
  9611.  
  9612.       for (i = maxvalue; i; i >>= 1)
  9613.     TYPE_PRECISION (enumtype)++;
  9614.  
  9615.       if (!TYPE_PRECISION (enumtype))
  9616.     TYPE_PRECISION (enumtype) = 1;
  9617.  
  9618.       /* Cancel the laying out previously done for the enum type,
  9619.      so that fixup_unsigned_type will do it over.  */
  9620.       TYPE_SIZE (enumtype) = 0;
  9621.  
  9622.       fixup_unsigned_type (enumtype);
  9623.     }
  9624.  
  9625.   TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue;
  9626.  
  9627.   /* An enum can have some negative values; then it is signed.  */
  9628.   if (minvalue < 0)
  9629.     {
  9630.       TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue;
  9631.       TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1;
  9632.       TREE_UNSIGNED (enumtype) = 0;
  9633.     }
  9634.   if (flag_cadillac)
  9635.     cadillac_finish_enum (enumtype);
  9636.  
  9637.   /* Finish debugging output for this type.  */
  9638. #if 0
  9639.   /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging
  9640.      information should *not* be generated?  I think not.  */
  9641.   if (! DECL_IGNORED_P (TYPE_NAME (enumtype)))
  9642. #endif
  9643.     rest_of_type_compilation (enumtype, global_bindings_p ());
  9644.  
  9645.   return enumtype;
  9646. }
  9647.  
  9648. /* Build and install a CONST_DECL for one value of the
  9649.    current enumeration type (one that was begun with start_enum).
  9650.    Return a tree-list containing the name and its value.
  9651.    Assignment of sequential values by default is handled here.  */
  9652.  
  9653. tree
  9654. build_enumerator (name, value)
  9655.      tree name, value;
  9656. {
  9657.   tree decl, result;
  9658.   /* Change this to zero if we find VALUE is not shareable.  */
  9659.   int shareable = 1;
  9660.  
  9661.   /* Validate and default VALUE.  */
  9662.   if (value != 0)
  9663.     {
  9664.       if (TREE_READONLY_DECL_P (value))
  9665.     {
  9666.       value = decl_constant_value (value);
  9667.       shareable = 0;
  9668.     }
  9669.  
  9670.       if (TREE_CODE (value) != INTEGER_CST)
  9671.     {
  9672.       error ("enumerator value for `%s' not integer constant",
  9673.          IDENTIFIER_POINTER (name));
  9674.       value = 0;
  9675.     }
  9676.     }
  9677.   /* The order of things is reversed here so that we
  9678.      can check for possible sharing of enum values,
  9679.      to keep that from happening.  */
  9680.   /* Default based on previous value.  */
  9681.   if (value == 0)
  9682.     value = enum_next_value;
  9683.  
  9684.   /* Remove no-op casts from the value.  */
  9685.   if (value)
  9686.     STRIP_TYPE_NOPS (value);
  9687.  
  9688.   /* Make up for hacks in cp-lex.c.  */
  9689.   if (value == integer_zero_node)
  9690.     value = build_int_2 (0, 0);
  9691.   else if (value == integer_one_node)
  9692.     value = build_int_2 (1, 0);
  9693.   else if (TREE_CODE (value) == INTEGER_CST
  9694.        && (shareable == 0
  9695.            || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
  9696.     {
  9697.       value = copy_node (value);
  9698.       TREE_TYPE (value) = integer_type_node;
  9699.     }
  9700.  
  9701.   result = saveable_tree_cons (name, value, NULL_TREE);
  9702.  
  9703.   /* C++ associates enums with global, function, or class declarations.  */
  9704.   if (current_class_type == NULL_TREE || current_function_decl != NULL_TREE)
  9705.     {
  9706.       /* Create a declaration for the enum value name.  */
  9707.  
  9708.       decl = build_decl (CONST_DECL, name, integer_type_node);
  9709.       DECL_INITIAL (decl) = value;
  9710.  
  9711.       pushdecl (decl);
  9712.       GNU_xref_decl (current_function_decl, decl);
  9713.     }
  9714.  
  9715.   /* Set basis for default for next value.  */
  9716.   enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
  9717.                            integer_one_node, PLUS_EXPR);
  9718.   if (enum_next_value == integer_one_node)
  9719.     enum_next_value = copy_node (enum_next_value);
  9720.  
  9721.   return result;
  9722. }
  9723.  
  9724. tree
  9725. grok_enum_decls (type, decl)
  9726.      tree type, decl;
  9727. {
  9728.   struct binding_level *b = class_binding_level;
  9729.   tree tag = NULL_TREE;
  9730.   tree values;
  9731.  
  9732.   while (b)
  9733.     {
  9734.       tag = value_member (type, b->tags);
  9735.       if (tag)
  9736.     break;
  9737.       b = b->level_chain;
  9738.     }
  9739.  
  9740.   if (b == 0 || (b != class_binding_level) || TREE_ADDRESSABLE (tag))
  9741.     return decl;
  9742.   else
  9743.     TREE_ADDRESSABLE (tag) = 1;
  9744.  
  9745.   values = TYPE_VALUES (type);
  9746.   while (values)
  9747.     {
  9748.       /* Create a declaration for the enum value name.  */
  9749.       tree next = build_lang_field_decl (CONST_DECL, TREE_PURPOSE (values), type);
  9750.       TREE_READONLY (next) = 1;
  9751.       DECL_INITIAL (next) = TREE_VALUE (values);
  9752.       TREE_CHAIN (next) = decl;
  9753.       decl = next;
  9754.       pushdecl_class_level (decl);
  9755.       values = TREE_CHAIN (values);
  9756.     }
  9757.   return decl;
  9758. }
  9759.  
  9760. /* Create the FUNCTION_DECL for a function definition.
  9761.    DECLSPECS and DECLARATOR are the parts of the declaration;
  9762.    they describe the function's name and the type it returns,
  9763.    but twisted together in a fashion that parallels the syntax of C.
  9764.  
  9765.    This function creates a binding context for the function body
  9766.    as well as setting up the FUNCTION_DECL in current_function_decl.
  9767.  
  9768.    Returns 1 on success.  If the DECLARATOR is not suitable for a function
  9769.    (it defines a datum instead), we return 0, which tells
  9770.    yyparse to report a parse error.
  9771.  
  9772.    For C++, we must first check whether that datum makes any sense.
  9773.    For example, "class A local_a(1,2);" means that variable local_a
  9774.    is an aggregate of type A, which should have a constructor
  9775.    applied to it with the argument list [1, 2].
  9776.  
  9777.    @@ There is currently no way to retrieve the storage
  9778.    @@ allocated to FUNCTION (or all of its parms) if we return
  9779.    @@ something we had previously.  */
  9780.  
  9781. int
  9782. start_function (declspecs, declarator, raises, pre_parsed_p)
  9783.      tree declarator, declspecs, raises;
  9784.      int pre_parsed_p;
  9785. {
  9786.   extern tree EHS_decl;
  9787.   tree decl1, olddecl;
  9788.   tree ctype = NULL_TREE;
  9789.   tree fntype;
  9790.   tree restype;
  9791.   extern int have_extern_spec;
  9792.   extern int used_extern_spec;
  9793.   int doing_friend = 0;
  9794.  
  9795.   if (flag_handle_exceptions && EHS_decl == NULL_TREE)
  9796.     init_exception_processing_1 ();
  9797.  
  9798.   /* Sanity check.  */
  9799.   my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160);
  9800.   my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
  9801.  
  9802.   /* Assume, until we see it does. */
  9803.   current_function_returns_value = 0;
  9804.   current_function_returns_null = 0;
  9805.   warn_about_return_type = 0;
  9806.   current_extern_inline = 0;
  9807.   current_function_assigns_this = 0;
  9808.   current_function_just_assigned_this = 0;
  9809.   current_function_parms_stored = 0;
  9810.   original_result_rtx = 0;
  9811.   current_function_obstack_index = 0;
  9812.   current_function_obstack_usage = 0;
  9813.  
  9814.   clear_temp_name ();
  9815.  
  9816.   /* This should only be done once on the top most decl. */
  9817.   if (have_extern_spec && !used_extern_spec)
  9818.     {
  9819.       declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
  9820.       used_extern_spec = 1;
  9821.     }
  9822.  
  9823.   if (pre_parsed_p)
  9824.     {
  9825.       decl1 = declarator;
  9826.       last_function_parms = DECL_ARGUMENTS (decl1);
  9827.       last_function_parm_tags = 0;
  9828.       fntype = TREE_TYPE (decl1);
  9829.       if (TREE_CODE (fntype) == METHOD_TYPE)
  9830.     ctype = TYPE_METHOD_BASETYPE (fntype);
  9831.  
  9832.       /* ANSI C++ June 5 1992 WP 11.4.5.  A friend function defined in a
  9833.      class is in the (lexical) scope of the class in which it is
  9834.      defined.  */
  9835.       if (!ctype && DECL_FRIEND_P (decl1))
  9836.     {
  9837.       ctype = TREE_TYPE (TREE_CHAIN (decl1));
  9838.       if (TREE_CODE (ctype) != RECORD_TYPE)
  9839.         ctype = NULL_TREE;
  9840.       else
  9841.         doing_friend = 1;
  9842.     }
  9843.  
  9844.       if ( !(DECL_VINDEX (decl1)
  9845.          && write_virtuals >= 2
  9846.          && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)))
  9847.     current_extern_inline = TREE_PUBLIC (decl1) && DECL_INLINE (decl1);
  9848.  
  9849.       raises = TYPE_RAISES_EXCEPTIONS (fntype);
  9850.  
  9851.       /* In a fcn definition, arg types must be complete.  */
  9852.       require_complete_types_for_parms (last_function_parms);
  9853.     }
  9854.   else
  9855.     {
  9856.       decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises);
  9857.       /* If the declarator is not suitable for a function definition,
  9858.      cause a syntax error.  */
  9859.       if (decl1 == 0 || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
  9860.  
  9861.       fntype = TREE_TYPE (decl1);
  9862.  
  9863.       restype = TREE_TYPE (fntype);
  9864.       if (IS_AGGR_TYPE (restype)
  9865.       && ! CLASSTYPE_GOT_SEMICOLON (restype))
  9866.     {
  9867.       error_with_aggr_type (restype, "semicolon missing after declaration of `%s'");
  9868.       shadow_tag (build_tree_list (NULL_TREE, restype));
  9869.       CLASSTYPE_GOT_SEMICOLON (restype) = 1;
  9870.       if (TREE_CODE (fntype) == FUNCTION_TYPE)
  9871.         fntype = build_function_type (integer_type_node,
  9872.                       TYPE_ARG_TYPES (fntype));
  9873.       else
  9874.         fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
  9875.                           integer_type_node,
  9876.                           TYPE_ARG_TYPES (fntype));
  9877.       TREE_TYPE (decl1) = fntype;
  9878.     }
  9879.  
  9880.       if (TREE_CODE (fntype) == METHOD_TYPE)
  9881.     ctype = TYPE_METHOD_BASETYPE (fntype);
  9882.       else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
  9883.            && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
  9884.            && DECL_CONTEXT (decl1) == NULL_TREE)
  9885.     {
  9886.       /* If this doesn't return integer_type, complain.  */
  9887.       if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
  9888.         {
  9889. #if 0
  9890.           error ("return type for `main' must be integer type");
  9891. #else
  9892.           warning ("return type for `main' changed to integer type");
  9893. #endif
  9894.           TREE_TYPE (decl1) = fntype = default_function_type;
  9895.         }
  9896.       warn_about_return_type = 0;
  9897.     }
  9898.     }
  9899.  
  9900.   /* Warn if function was previously implicitly declared
  9901.      (but not if we warned then).  */
  9902.   if (! warn_implicit && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != 0)
  9903.     warning_with_decl (IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)),
  9904.                "`%s' implicitly declared before its definition");
  9905.  
  9906.   current_function_decl = decl1;
  9907.  
  9908.   if (flag_cadillac)
  9909.     cadillac_start_function (decl1);
  9910.   else
  9911.     announce_function (decl1);
  9912.  
  9913.   if (TYPE_SIZE (TREE_TYPE (fntype)) == 0)
  9914.     {
  9915.       if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
  9916.     error_with_aggr_type (TREE_TYPE (fntype),
  9917.                   "return-type `%s' is an incomplete type");
  9918.       else
  9919.     error ("return-type is an incomplete type");
  9920.  
  9921.       /* Make it return void instead, but don't change the
  9922.      type of the DECL_RESULT, in case we have a named return value.  */
  9923.       if (ctype)
  9924.     TREE_TYPE (decl1)
  9925.       = build_cplus_method_type (build_type_variant (ctype, TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
  9926.                      void_type_node,
  9927.                      FUNCTION_ARG_CHAIN (decl1));
  9928.       else
  9929.     TREE_TYPE (decl1)
  9930.       = build_function_type (void_type_node,
  9931.                  TYPE_ARG_TYPES (TREE_TYPE (decl1)));
  9932.       DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, TREE_TYPE (fntype));
  9933.     }
  9934.  
  9935.   if (warn_about_return_type)
  9936.     warning ("return-type defaults to `int'");
  9937.  
  9938.   /* Make the init_value nonzero so pushdecl knows this is not tentative.
  9939.      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
  9940.   DECL_INITIAL (decl1) = error_mark_node;
  9941.  
  9942.   /* Didn't get anything from C.  */
  9943.   olddecl = 0;
  9944.  
  9945.   /* This function exists in static storage.
  9946.      (This does not mean `static' in the C sense!)  */
  9947.   TREE_STATIC (decl1) = 1;
  9948.  
  9949.   /* If this function belongs to an interface, it is public.
  9950.      If it belongs to someone else's interface, it is also external.
  9951.      It doesn't matter whether it's inline or not.  */
  9952.   if (interface_unknown == 0)
  9953.     {
  9954.       TREE_PUBLIC (decl1) = 1;
  9955.       DECL_EXTERNAL (decl1) = interface_only;
  9956.     }
  9957.   else
  9958.     /* This is a definition, not a reference.
  9959.        So normally clear DECL_EXTERNAL.
  9960.        However, `extern inline' acts like a declaration except for
  9961.        defining how to inline.  So set DECL_EXTERNAL in that case.  */
  9962.     DECL_EXTERNAL (decl1) = current_extern_inline;
  9963.  
  9964.   /* Now see if this is the implementation of a function
  9965.      declared with "C" linkage.  */
  9966.   if (ctype == NULL_TREE && current_lang_name == lang_name_cplusplus)
  9967.     {
  9968.       olddecl = lookup_name_current_level (DECL_NAME (decl1));
  9969.       if (olddecl && TREE_CODE (olddecl) != FUNCTION_DECL)
  9970.     olddecl = NULL_TREE;
  9971.       if (olddecl && DECL_NAME (decl1) != DECL_NAME (olddecl))
  9972.     {
  9973.       /* Collision between user and internal naming scheme.  */
  9974.       olddecl = lookup_name_current_level (DECL_ASSEMBLER_NAME (decl1));
  9975.       if (olddecl == NULL_TREE)
  9976.         olddecl = decl1;
  9977.     }
  9978.       if (olddecl && olddecl != decl1
  9979.       && DECL_NAME (decl1) == DECL_NAME (olddecl))
  9980.     {
  9981.       if (TREE_CODE (olddecl) == FUNCTION_DECL
  9982.           && (decls_match (decl1, olddecl)
  9983.           || comp_target_parms (TYPE_ARG_TYPES (TREE_TYPE (decl1)),
  9984.                     TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 1)))
  9985.         {
  9986.           olddecl = DECL_MAIN_VARIANT (olddecl);
  9987.           /* The following copy is needed to handle forcing a function's
  9988.          linkage to obey the linkage of the original decl.  */
  9989.           DECL_ASSEMBLER_NAME (decl1) = DECL_ASSEMBLER_NAME (olddecl);
  9990.           DECL_OVERLOADED (decl1) = DECL_OVERLOADED (olddecl);
  9991.           if (DECL_INITIAL (olddecl))
  9992.         redeclaration_error_message (decl1, olddecl);
  9993.           if (! duplicate_decls (decl1, olddecl))
  9994.         my_friendly_abort (19);
  9995.           decl1 = olddecl;
  9996.         }
  9997.       else
  9998.         olddecl = NULL_TREE;
  9999.     }
  10000.     }
  10001.  
  10002.   /* Record the decl so that the function name is defined.
  10003.      If we already have a decl for this name, and it is a FUNCTION_DECL,
  10004.      use the old decl.  */
  10005.  
  10006.   if (olddecl)
  10007.     current_function_decl = olddecl;
  10008.   else if (pre_parsed_p == 0)
  10009.     {
  10010.       current_function_decl = pushdecl (decl1);
  10011.       if (TREE_CODE (current_function_decl) == TREE_LIST)
  10012.     {
  10013.       /* @@ revert to modified original declaration.  */
  10014.       decl1 = DECL_MAIN_VARIANT (decl1);
  10015.       current_function_decl = decl1;
  10016.     }
  10017.       else
  10018.     {
  10019.       decl1 = current_function_decl;
  10020.       DECL_MAIN_VARIANT (decl1) = decl1;
  10021.     }
  10022.       fntype = TREE_TYPE (decl1);
  10023.     }
  10024.   else
  10025.     current_function_decl = decl1;
  10026.  
  10027.   if (DECL_OVERLOADED (decl1))
  10028.     decl1 = push_overloaded_decl (decl1, 1);
  10029.  
  10030.   if (ctype != 0 && DECL_STATIC_FUNCTION_P (decl1))
  10031.     {
  10032.       if (TREE_CODE (fntype) == METHOD_TYPE)
  10033.     TREE_TYPE (decl1) = fntype
  10034.       = build_function_type (TREE_TYPE (fntype),
  10035.                  TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
  10036.       last_function_parms = TREE_CHAIN (last_function_parms);
  10037.       DECL_ARGUMENTS (decl1) = last_function_parms;
  10038.       ctype = 0;
  10039.     }
  10040.   restype = TREE_TYPE (fntype);
  10041.  
  10042.   pushlevel (0);
  10043.   current_binding_level->parm_flag = 1;
  10044.  
  10045.   /* Save the parm names or decls from this function's declarator
  10046.      where store_parm_decls will find them.  */
  10047.   current_function_parms = last_function_parms;
  10048.   current_function_parm_tags = last_function_parm_tags;
  10049.  
  10050.   GNU_xref_function (decl1, current_function_parms);
  10051.  
  10052.   make_function_rtl (decl1);
  10053.  
  10054.   if (ctype)
  10055.     {
  10056.       pushclass (ctype, 1);
  10057.  
  10058.       /* If we're compiling a friend function, neither of the variables
  10059.      current_class_decl nor current_class_type will have values.  */
  10060.       if (! doing_friend)
  10061.     {
  10062.       /* We know that this was set up by `grokclassfn'.
  10063.          We do not wait until `store_parm_decls', since evil
  10064.          parse errors may never get us to that point.  Here
  10065.          we keep the consistency between `current_class_type'
  10066.          and `current_class_decl'.  */
  10067.       current_class_decl = last_function_parms;
  10068.       my_friendly_assert (current_class_decl != NULL_TREE
  10069.           && TREE_CODE (current_class_decl) == PARM_DECL, 162);
  10070.       if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE)
  10071.         {
  10072.           tree variant = TREE_TYPE (TREE_TYPE (current_class_decl));
  10073.           if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE)
  10074.         {
  10075.           /* Can't call build_indirect_ref here, because it has special
  10076.              logic to return C_C_D given this argument.  */
  10077.           C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl);
  10078.           CLASSTYPE_INST_VAR (ctype) = C_C_D;
  10079.         }
  10080.           else
  10081.         {
  10082.           C_C_D = CLASSTYPE_INST_VAR (ctype);
  10083.           /* `current_class_decl' is different for every
  10084.              function we compile.  */
  10085.           TREE_OPERAND (C_C_D, 0) = current_class_decl;
  10086.         }
  10087.           TREE_READONLY (C_C_D) = TYPE_READONLY (variant);
  10088.           TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (variant);
  10089.           TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (variant);
  10090.         }
  10091.       else
  10092.         C_C_D = current_class_decl;
  10093.     }
  10094.     }
  10095.   else
  10096.     {
  10097.       if (DECL_STATIC_FUNCTION_P (decl1))
  10098.     pushclass (DECL_CONTEXT (decl1), 2);
  10099.       else
  10100.     push_memoized_context (0, 1);
  10101.     }
  10102.  
  10103.   /* Allocate further tree nodes temporarily during compilation
  10104.      of this function only.  Tiemann moved up here from bottom of fn.  */
  10105.   temporary_allocation ();
  10106.  
  10107.   /* Promote the value to int before returning it.  */
  10108.   if (C_PROMOTING_INTEGER_TYPE_P (restype))
  10109.     {
  10110.       /* It retains unsignedness if traditional or if it isn't
  10111.      really getting wider.  */
  10112.       if (TREE_UNSIGNED (restype)
  10113.       && (flag_traditional
  10114.           || TYPE_PRECISION (restype)
  10115.            == TYPE_PRECISION (integer_type_node)))
  10116.     restype = unsigned_type_node;
  10117.       else
  10118.     restype = integer_type_node;
  10119.     }
  10120. #ifdef APPLE_HAX
  10121.   /* All float types automagically become extended. */
  10122.   if (TREE_CODE (restype) == REAL_TYPE && flag_apple)
  10123.     restype = long_double_type_node;
  10124. #endif /* APPLE_HAX */
  10125.   if (DECL_RESULT (decl1) == NULL_TREE)
  10126.     DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, restype);
  10127.  
  10128.   if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)))
  10129.     {
  10130.       dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  10131.       ctor_label = NULL_TREE;
  10132.     }
  10133.   else
  10134.     {
  10135.       dtor_label = NULL_TREE;
  10136.       if (DECL_CONSTRUCTOR_P (decl1))
  10137.     ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  10138.     }
  10139.  
  10140.   /* If this fcn was already referenced via a block-scope `extern' decl
  10141.      (or an implicit decl), propagate certain information about the usage.  */
  10142.   if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
  10143.     TREE_ADDRESSABLE (decl1) = 1;
  10144.  
  10145. #ifdef MPW_ASM
  10146.   /* Start on collecting names for this function module. */
  10147.   start_module (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
  10148. #endif /* MPW_ASM */
  10149.  
  10150.   return 1;
  10151. }
  10152.  
  10153. /* Store the parameter declarations into the current function declaration.
  10154.    This is called after parsing the parameter declarations, before
  10155.    digesting the body of the function.
  10156.  
  10157.    Also install to binding contour return value identifier, if any.  */
  10158.  
  10159. void
  10160. store_parm_decls ()
  10161. {
  10162.   register tree fndecl = current_function_decl;
  10163.   register tree parm;
  10164.   int parms_have_cleanups = 0;
  10165.   tree eh_decl;
  10166.  
  10167.   /* This is either a chain of PARM_DECLs (when a prototype is used).  */
  10168.   tree specparms = current_function_parms;
  10169.  
  10170.   /* This is a list of types declared among parms in a prototype.  */
  10171.   tree parmtags = current_function_parm_tags;
  10172.  
  10173.   /* This is a chain of any other decls that came in among the parm
  10174.      declarations.  If a parm is declared with  enum {foo, bar} x;
  10175.      then CONST_DECLs for foo and bar are put here.  */
  10176.   tree nonparms = 0;
  10177.  
  10178.   if (current_binding_level == global_binding_level)
  10179.     fatal ("parse errors have confused me too much");
  10180.  
  10181.   /* Initialize RTL machinery.  */
  10182.   init_function_start (fndecl, input_filename, lineno);
  10183.  
  10184.   /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function.  */
  10185.   declare_function_name ();
  10186.  
  10187.   /* Create a binding level for the parms.  */
  10188.   expand_start_bindings (0);
  10189.  
  10190.   /* Prepare to catch raises, if appropriate.  */
  10191.   if (flag_handle_exceptions)
  10192.     {
  10193.       /* Get this cleanup to be run last, since it
  10194.      is a call to `longjmp'.  */
  10195.       setup_exception_throw_decl ();
  10196.       eh_decl = current_binding_level->names;
  10197.       current_binding_level->names = TREE_CHAIN (current_binding_level->names);
  10198.     }
  10199.   if (flag_handle_exceptions)
  10200.     expand_start_try (integer_one_node, 0, 1);
  10201.  
  10202.   if (specparms != 0)
  10203.     {
  10204.       /* This case is when the function was defined with an ANSI prototype.
  10205.      The parms already have decls, so we need not do anything here
  10206.      except record them as in effect
  10207.      and complain if any redundant old-style parm decls were written.  */
  10208.  
  10209.       register tree next;
  10210.  
  10211.       /* Must clear this because it might contain TYPE_DECLs declared
  10212.      at class level.  */
  10213.       storedecls (NULL_TREE);
  10214.       for (parm = nreverse (specparms); parm; parm = next)
  10215.     {
  10216.       next = TREE_CHAIN (parm);
  10217.       if (TREE_CODE (parm) == PARM_DECL)
  10218.         {
  10219.           tree cleanup = maybe_build_cleanup (parm);
  10220.           if (DECL_NAME (parm) == 0)
  10221.         {
  10222. #if 0
  10223.           error_with_decl (parm, "parameter name omitted");
  10224. #else
  10225.           /* for C++, this is not an error.  */
  10226.           pushdecl (parm);
  10227. #endif
  10228.         }
  10229.           else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
  10230.         error_with_decl (parm, "parameter `%s' declared void");
  10231.           else
  10232.         {
  10233.           /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
  10234.              A parameter is assumed not to have any side effects.
  10235.              If this should change for any reason, then this
  10236.              will have to wrap the bashed reference type in a save_expr.
  10237.              
  10238.              Also, if the parameter type is declared to be an X
  10239.              and there is an X(X&) constructor, we cannot lay it
  10240.              into the stack (any more), so we make this parameter
  10241.              look like it is really of reference type.  Functions
  10242.              which pass parameters to this function will know to
  10243.              create a temporary in their frame, and pass a reference
  10244.              to that.  */
  10245.  
  10246.           if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
  10247.               && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
  10248.             SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
  10249.  
  10250.           pushdecl (parm);
  10251.         }
  10252.           if (cleanup)
  10253.         {
  10254.           expand_decl (parm);
  10255.           expand_decl_cleanup (parm, cleanup);
  10256.           parms_have_cleanups = 1;
  10257.         }
  10258.         }
  10259.       else
  10260.         {
  10261.           /* If we find an enum constant or a type tag,
  10262.          put it aside for the moment.  */
  10263.           TREE_CHAIN (parm) = 0;
  10264.           nonparms = chainon (nonparms, parm);
  10265.         }
  10266.     }
  10267.  
  10268.       /* Get the decls in their original chain order
  10269.      and record in the function.  This is all and only the
  10270.      PARM_DECLs that were pushed into scope by the loop above.  */
  10271.       DECL_ARGUMENTS (fndecl) = getdecls ();
  10272.  
  10273.       storetags (chainon (parmtags, gettags ()));
  10274.     }
  10275.   else
  10276.     DECL_ARGUMENTS (fndecl) = 0;
  10277.  
  10278.   /* Now store the final chain of decls for the arguments
  10279.      as the decl-chain of the current lexical scope.
  10280.      Put the enumerators in as well, at the front so that
  10281.      DECL_ARGUMENTS is not modified.  */
  10282.  
  10283.   storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
  10284.  
  10285.   /* Initialize the RTL code for the function.  */
  10286.   DECL_SAVED_INSNS (fndecl) = 0;
  10287.   expand_function_start (fndecl, parms_have_cleanups);
  10288.  
  10289.   if (flag_handle_exceptions)
  10290.     {
  10291.       /* Make the throw decl visible at this level, just
  10292.      not in the way of the parameters.  */
  10293.       pushdecl (eh_decl);
  10294.       expand_decl_init (eh_decl);
  10295.     }
  10296.  
  10297.   /* Create a binding contour which can be used to catch
  10298.      cleanup-generated temporaries.  Also, if the return value needs or
  10299.      has initialization, deal with that now.  */
  10300.   if (parms_have_cleanups)
  10301.     {
  10302.       pushlevel (0);
  10303.       expand_start_bindings (0);
  10304.     }
  10305.  
  10306.   current_function_parms_stored = 1;
  10307.  
  10308.   if (flag_gc)
  10309.     {
  10310.       maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node);
  10311.       expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup);
  10312.     }
  10313.  
  10314.   /* If this function is `main', emit a call to `__main'
  10315.      to run global initializers, etc.  */
  10316.   if (DECL_NAME (fndecl)
  10317.       && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
  10318.       && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
  10319.       && DECL_CONTEXT (fndecl) == NULL_TREE)
  10320.     {
  10321.       expand_main_function ();
  10322.  
  10323.       if (flag_gc)
  10324.     expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE),
  10325.              0, VOIDmode, 0);
  10326.  
  10327.       if (flag_dossier)
  10328.     output_builtin_tdesc_entries ();
  10329.     }
  10330. }
  10331.  
  10332. /* Bind a name and initialization to the return value of
  10333.    the current function.  */
  10334. void
  10335. store_return_init (return_id, init)
  10336.      tree return_id, init;
  10337. {
  10338.   tree decl = DECL_RESULT (current_function_decl);
  10339.  
  10340.   if (pedantic)
  10341.     /* Give this error as many times as there are occurrences,
  10342.        so that users can use Emacs compilation buffers to find
  10343.        and fix all such places.  */
  10344.     error ("ANSI C++ does not permit named return values");
  10345.  
  10346.   if (return_id != NULL_TREE)
  10347.     {
  10348.       if (DECL_NAME (decl) == 0)
  10349.     {
  10350.       DECL_NAME (decl) = return_id;
  10351.       DECL_ASSEMBLER_NAME (decl) = return_id;
  10352.     }
  10353.       else
  10354.     error ("return identifier `%s' already in place",
  10355.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  10356.     }
  10357.  
  10358.   /* Can't let this happen for constructors.  */
  10359.   if (DECL_CONSTRUCTOR_P (current_function_decl))
  10360.     {
  10361.       error ("can't redefine default return value for constructors");
  10362.       return;
  10363.     }
  10364.  
  10365.   /* If we have a named return value, put that in our scope as well.  */
  10366.   if (DECL_NAME (decl) != 0)
  10367.     {
  10368.       /* If this named return value comes in a register,
  10369.      put it in a pseudo-register.  */
  10370.       if (DECL_REGISTER (decl))
  10371.     {
  10372.       original_result_rtx = DECL_RTL (decl);
  10373.       DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
  10374.     }
  10375.  
  10376.       /* Let `finish_decl' know that this initializer is ok.  */
  10377.       DECL_INITIAL (decl) = init;
  10378.       pushdecl (decl);
  10379.       finish_decl (decl, init, 0, 0);
  10380.     }
  10381. }
  10382.  
  10383. /* Generate code for default X(X&) constructor.  */
  10384. static void
  10385. build_default_constructor (fndecl)
  10386.      tree fndecl;
  10387. {
  10388.   int i = CLASSTYPE_N_BASECLASSES (current_class_type);
  10389.   tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
  10390.   tree fields = TYPE_FIELDS (current_class_type);
  10391.   tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
  10392.  
  10393.   if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  10394.     parm = TREE_CHAIN (parm);
  10395.   parm = DECL_REFERENCE_SLOT (parm);
  10396.  
  10397.   while (--i >= 0)
  10398.     {
  10399.       tree basetype = TREE_VEC_ELT (binfos, i);
  10400.       if (TYPE_GETS_INIT_REF (basetype))
  10401.     {
  10402.       tree name = TYPE_NAME (basetype);
  10403.       if (TREE_CODE (name) == TYPE_DECL)
  10404.         name = DECL_NAME (name);
  10405.       current_base_init_list = tree_cons (name, parm, current_base_init_list);
  10406.     }
  10407.     }
  10408.   for (; fields; fields = TREE_CHAIN (fields))
  10409.     {
  10410.       tree name, init;
  10411.       if (TREE_STATIC (fields))
  10412.     continue;
  10413.       if (TREE_CODE (fields) != FIELD_DECL)
  10414.     continue;
  10415.       if (DECL_NAME (fields))
  10416.     {
  10417.       if (VFIELD_NAME_P (DECL_NAME (fields)))
  10418.         continue;
  10419.       if (VBASE_NAME_P (DECL_NAME (fields)))
  10420.         continue;
  10421.  
  10422.       /* True for duplicate members.  */
  10423.       if (IDENTIFIER_CLASS_VALUE (DECL_NAME (fields)) != fields)
  10424.         continue;
  10425.     }
  10426.  
  10427.       init = build (COMPONENT_REF, TREE_TYPE (fields), parm, fields);
  10428.  
  10429.       if (TREE_ANON_UNION_ELEM (fields))
  10430.     name = build (COMPONENT_REF, TREE_TYPE (fields), C_C_D, fields);
  10431.       else
  10432.     {
  10433.       name = DECL_NAME (fields);
  10434.       init = build_tree_list (NULL_TREE, init);
  10435.     }
  10436.  
  10437.       current_member_init_list
  10438.     = tree_cons (name, init, current_member_init_list);
  10439.     }
  10440. }
  10441.  
  10442.  
  10443. /* Finish up a function declaration and compile that function
  10444.    all the way to assembler language output.  The free the storage
  10445.    for the function definition.
  10446.  
  10447.    This is called after parsing the body of the function definition.
  10448.    LINENO is the current line number.
  10449.  
  10450.    C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
  10451.    (and expand_end_bindings) must be made to take care of the binding
  10452.    contour for the base initializers.  This is only relevant for
  10453.    constructors.  */
  10454.  
  10455. void
  10456. finish_function (lineno, call_poplevel)
  10457.      int lineno;
  10458.      int call_poplevel;
  10459. {
  10460.   register tree fndecl = current_function_decl;
  10461.   tree fntype = TREE_TYPE (fndecl), ctype = NULL_TREE;
  10462.   rtx head, last_parm_insn, mark;
  10463.   extern int sets_exception_throw_decl;
  10464.   /* Label to use if this function is supposed to return a value.  */
  10465.   tree no_return_label = 0;
  10466.  
  10467. /*  TREE_READONLY (fndecl) = 1;
  10468.     This caused &foo to be of type ptr-to-const-function
  10469.     which then got a warning when stored in a ptr-to-function variable.  */
  10470.  
  10471.   /* This happens on strange parse errors.  */
  10472.   if (! current_function_parms_stored)
  10473.     {
  10474.       call_poplevel = 0;
  10475.       store_parm_decls ();
  10476.     }
  10477.  
  10478.   if (write_symbols != NO_DEBUG && TREE_CODE (fntype) != METHOD_TYPE)
  10479.     {
  10480.       tree ttype = target_type (fntype);
  10481.       tree parmdecl;
  10482.  
  10483.       if (IS_AGGR_TYPE (ttype))
  10484.     /* Let debugger know it should output info for this type.  */
  10485.     note_debug_info_needed (ttype);
  10486.  
  10487.       for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
  10488.     {
  10489.       ttype = target_type (TREE_TYPE (parmdecl));
  10490.       if (IS_AGGR_TYPE (ttype))
  10491.         /* Let debugger know it should output info for this type.  */
  10492.         note_debug_info_needed (ttype);
  10493.     }
  10494.     }
  10495.  
  10496.   /* Clean house because we will need to reorder insns here.  */
  10497.   do_pending_stack_adjust ();
  10498.  
  10499.   if (dtor_label)
  10500.     {
  10501.       tree binfo = TYPE_BINFO (current_class_type);
  10502.       tree cond = integer_one_node;
  10503.       tree exprstmt, vfields;
  10504.       tree in_charge_node = lookup_name (in_charge_identifier, 0);
  10505.       tree virtual_size;
  10506.       int ok_to_optimize_dtor = 0;
  10507.  
  10508.       if (current_function_assigns_this)
  10509.     cond = build (NE_EXPR, integer_type_node,
  10510.               current_class_decl, integer_zero_node);
  10511.       else
  10512.     {
  10513.       int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
  10514.  
  10515.       /* If this destructor is empty, then we don't need to check
  10516.          whether `this' is NULL in some cases.  */
  10517.       mark = get_last_insn ();
  10518.       last_parm_insn = get_first_nonparm_insn ();
  10519.  
  10520.       if ((flag_this_is_variable & 1) == 0)
  10521.         ok_to_optimize_dtor = 1;
  10522.       else if (mark == last_parm_insn)
  10523.         ok_to_optimize_dtor
  10524.           = (n_baseclasses == 0
  10525.          || (n_baseclasses == 1
  10526.              && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
  10527.     }
  10528.  
  10529.       /* These initializations might go inline.  Protect
  10530.      the binding level of the parms.  */
  10531.       pushlevel (0);
  10532.  
  10533.       if (current_function_assigns_this)
  10534.     {
  10535.       current_function_assigns_this = 0;
  10536.       current_function_just_assigned_this = 0;
  10537.     }
  10538.  
  10539.       /* Generate the code to call destructor on base class.
  10540.      If this destructor belongs to a class with virtual
  10541.      functions, then set the virtual function table
  10542.      pointer to represent the type of our base class.  */
  10543.  
  10544.       /* This side-effect makes call to `build_delete' generate the
  10545.      code we have to have at the end of this destructor.  */
  10546.       TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
  10547.  
  10548.       /* These are two cases where we cannot delegate deletion.  */
  10549.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
  10550.       || TREE_GETS_DELETE (current_class_type))
  10551.     exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
  10552.                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0, 0);
  10553.       else
  10554.     exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
  10555.                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0, 0);
  10556.  
  10557.       /* If we did not assign to this, then `this' is non-zero at
  10558.      the end of a destructor.  As a special optimization, don't
  10559.      emit test if this is an empty destructor.  If it does nothing,
  10560.      it does nothing.  If it calls a base destructor, the base
  10561.      destructor will perform the test.  */
  10562.  
  10563.       if (exprstmt != error_mark_node
  10564.       && (TREE_CODE (exprstmt) != NOP_EXPR
  10565.           || TREE_OPERAND (exprstmt, 0) != integer_zero_node
  10566.           || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
  10567.     {
  10568.       expand_label (dtor_label);
  10569.       if (cond != integer_one_node)
  10570.         expand_start_cond (cond, 0);
  10571.       if (exprstmt != void_zero_node)
  10572.         /* Don't call `expand_expr_stmt' if we're not going to do
  10573.            anything, since -Wall will give a diagnostic.  */
  10574.         expand_expr_stmt (exprstmt);
  10575.  
  10576.       /* Run destructor on all virtual baseclasses.  */
  10577.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  10578.         {
  10579.           tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
  10580.           expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
  10581.                     in_charge_node, integer_two_node), 0);
  10582.           while (vbases)
  10583.         {
  10584.           if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
  10585.             {
  10586.               tree ptr = convert_pointer_to_vbase (vbases, current_class_decl);
  10587.               expand_expr_stmt (build_delete (TYPE_POINTER_TO (BINFO_TYPE (vbases)),
  10588.                               ptr, integer_zero_node,
  10589.                               LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0, 0));
  10590.             }
  10591.           vbases = TREE_CHAIN (vbases);
  10592.         }
  10593.           expand_end_cond ();
  10594.         }
  10595.  
  10596.       do_pending_stack_adjust ();
  10597.       if (cond != integer_one_node)
  10598.         expand_end_cond ();
  10599.     }
  10600.  
  10601.       TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
  10602.  
  10603.       virtual_size = c_sizeof (current_class_type);
  10604.  
  10605.       /* At the end, call delete if that's what's requested.  */
  10606.       if (TREE_GETS_DELETE (current_class_type))
  10607.     /* This NOP_EXPR means we are in a static call context.  */
  10608.     exprstmt =
  10609.       build_method_call
  10610.         (build1 (NOP_EXPR,
  10611.              TYPE_POINTER_TO (current_class_type), error_mark_node),
  10612.          ansi_opname[(int) DELETE_EXPR],
  10613.          tree_cons (NULL_TREE, current_class_decl,
  10614.             build_tree_list (NULL_TREE, virtual_size)),
  10615.          NULL_TREE, LOOKUP_NORMAL);
  10616.       else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  10617.     exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0,
  10618.                    virtual_size);
  10619.       else
  10620.     exprstmt = 0;
  10621.  
  10622.       if (exprstmt)
  10623.     {
  10624.       cond = build (BIT_AND_EXPR, integer_type_node,
  10625.             in_charge_node, integer_one_node);
  10626.       expand_start_cond (cond, 0);
  10627.       expand_expr_stmt (exprstmt);
  10628.       expand_end_cond ();
  10629.     }
  10630.  
  10631.       /* End of destructor.  */
  10632.       poplevel (2, 0, 0);
  10633.  
  10634.       /* Back to the top of destructor.  */
  10635.       /* Dont execute destructor code if `this' is NULL.  */
  10636.       mark = get_last_insn ();
  10637.       last_parm_insn = get_first_nonparm_insn ();
  10638.       if (last_parm_insn == 0)
  10639.     last_parm_insn = mark;
  10640.       else
  10641.     last_parm_insn = previous_insn (last_parm_insn);
  10642.  
  10643.       /* Make all virtual function table pointers point to CURRENT_CLASS_TYPE's
  10644.      virtual function tables.  */
  10645.       if (CLASSTYPE_VFIELDS (current_class_type))
  10646.     {
  10647.       for (vfields = CLASSTYPE_VFIELDS (current_class_type);
  10648.            TREE_CHAIN (vfields);
  10649.            vfields = TREE_CHAIN (vfields))
  10650.         {
  10651.           tree vf_decl = current_class_decl;
  10652.           /* ??? This may need to be a loop if there are multiple
  10653.          levels of replication.  */
  10654.           if (VF_BINFO_VALUE (vfields))
  10655.         vf_decl = convert_pointer_to (VF_BINFO_VALUE (vfields), vf_decl);
  10656.           if (vf_decl != error_mark_node)
  10657.         expand_expr_stmt (build_virtual_init (binfo,
  10658.                               VF_BASETYPE_VALUE (vfields),
  10659.                               vf_decl));
  10660.         }
  10661.       expand_expr_stmt (build_virtual_init (binfo, binfo,
  10662.                         current_class_decl));
  10663.     }
  10664.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  10665.     expand_expr_stmt (build_vbase_vtables_init (binfo, binfo,
  10666.                             C_C_D, current_class_decl, 0));
  10667.       if (! ok_to_optimize_dtor)
  10668.     {
  10669.       cond = build_binary_op (NE_EXPR, current_class_decl, integer_zero_node);
  10670.       expand_start_cond (cond, 0);
  10671.     }
  10672.       if (mark != get_last_insn ())
  10673.     reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
  10674.       if (! ok_to_optimize_dtor)
  10675.     expand_end_cond ();
  10676.     }
  10677.   else if (current_function_assigns_this)
  10678.     {
  10679.       /* Does not need to call emit_base_init, because
  10680.      that is done (if needed) just after assignment to this
  10681.      is seen.  */
  10682.  
  10683.       if (DECL_CONSTRUCTOR_P (current_function_decl))
  10684.     {
  10685.       expand_label (ctor_label);
  10686.       ctor_label = NULL_TREE;
  10687.  
  10688.       if (call_poplevel)
  10689.         {
  10690.           tree decls = getdecls ();
  10691.           if (flag_handle_exceptions == 2)
  10692.         deactivate_exception_cleanups ();
  10693.           expand_end_bindings (decls, decls != 0, 0);
  10694.           poplevel (decls != 0, 0, 0);
  10695.         }
  10696.       c_expand_return (current_class_decl);
  10697.     }
  10698.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (
  10699.             DECL_RESULT (current_function_decl))) != void_type_node
  10700.            && return_label != NULL)
  10701.     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  10702.  
  10703.       current_function_assigns_this = 0;
  10704.       current_function_just_assigned_this = 0;
  10705.       base_init_insns = 0;
  10706.     }
  10707.   else if (DECL_CONSTRUCTOR_P (fndecl))
  10708.     {
  10709.       tree allocated_this;
  10710.       tree cond, thenclause;
  10711.       /* Allow constructor for a type to get a new instance of the object
  10712.      using `build_new'.  */
  10713.       tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
  10714.       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
  10715.  
  10716.       DECL_RETURNS_FIRST_ARG (fndecl) = 1;
  10717.  
  10718.       if (flag_this_is_variable > 0)
  10719.     {
  10720.       cond = build_binary_op (EQ_EXPR, current_class_decl, integer_zero_node);
  10721.       thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
  10722.                       build_new (NULL_TREE, current_class_type, void_type_node, 0));
  10723.       if (flag_handle_exceptions == 2)
  10724.         {
  10725.           tree cleanup, cleanup_deallocate;
  10726.           tree virtual_size;
  10727.  
  10728.           /* This is the size of the virtual object pointed to by
  10729.          allocated_this.  In this case, it is simple.  */
  10730.           virtual_size = c_sizeof (current_class_type);
  10731.  
  10732.           allocated_this = build_decl (VAR_DECL, NULL_TREE, ptr_type_node);
  10733.           DECL_REGISTER (allocated_this) = 1;
  10734.           DECL_INITIAL (allocated_this) = error_mark_node;
  10735.           expand_decl (allocated_this);
  10736.           expand_decl_init (allocated_this);
  10737.           /* How we cleanup `this' if an exception was raised before
  10738.          we are ready to bail out.  */
  10739.           cleanup = TREE_GETS_DELETE (current_class_type)
  10740.         ? build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, allocated_this, virtual_size)
  10741.           /* The size of allocated_this is wrong, and hence the
  10742.              second argument to operator delete will be wrong. */
  10743.           : build_delete (TREE_TYPE (allocated_this), allocated_this,
  10744.                   integer_three_node,
  10745.                   LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, 1, 0);
  10746.           cleanup_deallocate
  10747.         = build_modify_expr (current_class_decl, NOP_EXPR, integer_zero_node);
  10748.           cleanup = tree_cons (NULL_TREE, cleanup,
  10749.                    build_tree_list (NULL_TREE, cleanup_deallocate));
  10750.  
  10751.           expand_decl_cleanup (allocated_this,
  10752.                    build (COND_EXPR, integer_type_node,
  10753.                       build (NE_EXPR, integer_type_node,
  10754.                          allocated_this, integer_zero_node),
  10755.                       build_compound_expr (cleanup),
  10756.                       integer_zero_node));
  10757.         }
  10758.     }
  10759.       else if (TREE_GETS_NEW (current_class_type))
  10760.     /* Just check visibility here.  */
  10761.     build_method_call (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type), error_mark_node),
  10762.                ansi_opname[(int) NEW_EXPR],
  10763.                build_tree_list (NULL_TREE, integer_zero_node),
  10764.                NULL_TREE, LOOKUP_NORMAL);
  10765.  
  10766.       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
  10767.  
  10768.       /* must keep the first insn safe.  */
  10769.       head = get_insns ();
  10770.  
  10771.       /* this note will come up to the top with us.  */
  10772.       mark = get_last_insn ();
  10773.  
  10774.       if (flag_this_is_variable > 0)
  10775.     {
  10776.       expand_start_cond (cond, 0);
  10777.       expand_expr_stmt (thenclause);
  10778.       if (flag_handle_exceptions == 2)
  10779.         expand_assignment (allocated_this, current_class_decl, 0, 0);
  10780.       expand_end_cond ();
  10781.     }
  10782.  
  10783.       if (DECL_NAME (fndecl) == NULL_TREE
  10784.       && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
  10785.     build_default_constructor (fndecl);
  10786.  
  10787.       /* Emit insns from `emit_base_init' which sets up virtual
  10788.      function table pointer(s).  */
  10789.       emit_insns (base_init_insns);
  10790.       base_init_insns = 0;
  10791.  
  10792.       /* This is where the body of the constructor begins.
  10793.      If there were no insns in this function body, then the
  10794.      last_parm_insn is also the last insn.
  10795.  
  10796.      If optimization is enabled, last_parm_insn may move, so
  10797.      we don't hold on to it (across emit_base_init).  */
  10798.       last_parm_insn = get_first_nonparm_insn ();
  10799.       if (last_parm_insn == 0) last_parm_insn = mark;
  10800.       else last_parm_insn = previous_insn (last_parm_insn);
  10801.  
  10802.       if (mark != get_last_insn ())
  10803.     reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
  10804.  
  10805.       /* This is where the body of the constructor ends.  */
  10806.       expand_label (ctor_label);
  10807.       ctor_label = NULL_TREE;
  10808.       if (flag_handle_exceptions == 2)
  10809.     {
  10810.       expand_assignment (allocated_this, integer_zero_node, 0, 0);
  10811.       if (call_poplevel)
  10812.         deactivate_exception_cleanups ();
  10813.     }
  10814.  
  10815.       pop_implicit_try_blocks (NULL_TREE);
  10816.  
  10817.       if (call_poplevel)
  10818.     {
  10819.       expand_end_bindings (getdecls (), 1, 0);
  10820.       poplevel (1, 1, 0);
  10821.     }
  10822.  
  10823.       c_expand_return (current_class_decl);
  10824.  
  10825.       current_function_assigns_this = 0;
  10826.       current_function_just_assigned_this = 0;
  10827.     }
  10828.   else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
  10829.        && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
  10830.        && DECL_CONTEXT (fndecl) == NULL_TREE)
  10831.     {
  10832.       /* Make it so that `main' always returns 0 by default.  */
  10833. #ifdef VMS
  10834.       c_expand_return (integer_one_node);
  10835. #else
  10836.       c_expand_return (integer_zero_node);
  10837. #endif
  10838.     }
  10839.   else if (return_label != NULL
  10840.        && current_function_return_value == 0
  10841.        && ! DECL_NAME (DECL_RESULT (current_function_decl)))
  10842.     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  10843.  
  10844.   if (flag_gc)
  10845.     expand_gc_prologue_and_epilogue ();
  10846.  
  10847.   /* That's the end of the vtable decl's life.  Need to mark it such
  10848.      if doing stupid register allocation.
  10849.  
  10850.      Note that current_vtable_decl is really an INDIRECT_REF
  10851.      on top of a VAR_DECL here.  */
  10852.   if (obey_regdecls && current_vtable_decl)
  10853.     use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0)));
  10854.  
  10855.   /* If this function is supposed to return a value, ensure that
  10856.      we do not fall into the cleanups by mistake.  The end of our
  10857.      function will look like this:
  10858.  
  10859.     user code (may have return stmt somewhere)
  10860.     goto no_return_label
  10861.     cleanup_label:
  10862.     cleanups
  10863.     goto return_label
  10864.     no_return_label:
  10865.     NOTE_INSN_FUNCTION_END
  10866.     return_label:
  10867.     things for return
  10868.  
  10869.      If the user omits a return stmt in the USER CODE section, we
  10870.      will have a control path which reaches NOTE_INSN_FUNCTION_END.
  10871.      Otherwise, we won't.  */
  10872.   if (no_return_label)
  10873.     {
  10874.       DECL_CONTEXT (no_return_label) = fndecl;
  10875.       DECL_INITIAL (no_return_label) = error_mark_node;
  10876.       DECL_SOURCE_FILE (no_return_label) = input_filename;
  10877.       DECL_SOURCE_LINE (no_return_label) = lineno;
  10878.       expand_goto (no_return_label);
  10879.     }
  10880.  
  10881.   if (cleanup_label)
  10882.     {
  10883.       /* remove the binding contour which is used
  10884.      to catch cleanup-generated temporaries.  */
  10885.       expand_end_bindings (0, 0, 0);
  10886.       poplevel (0, 0, 0);
  10887.     }
  10888.  
  10889.   /* Must mark the RESULT_DECL as being in this function.  */
  10890.   DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
  10891.  
  10892.   /* Obey `register' declarations if `setjmp' is called in this fn.  */
  10893.   if (flag_traditional && current_function_calls_setjmp)
  10894.     setjmp_protect (DECL_INITIAL (fndecl));
  10895.  
  10896.   if (cleanup_label)
  10897.     /* Emit label at beginning of cleanup code for parameters.  */
  10898.     emit_label (cleanup_label);
  10899.  
  10900. #if 1
  10901.   /* Cheap hack to get better code from GNU C++.  Remove when cse is fixed.  */
  10902.   if (exception_throw_decl && sets_exception_throw_decl == 0)
  10903.     expand_assignment (exception_throw_decl, integer_zero_node, 0, 0);
  10904. #endif
  10905.  
  10906.   if (flag_handle_exceptions)
  10907.     {
  10908.       expand_end_try ();
  10909.       expand_start_except (0, 0);
  10910.       expand_end_except ();
  10911.     }
  10912.   expand_end_bindings (0, 0, 0);
  10913.  
  10914.   /* Get return value into register if that's where it's supposed to be.  */
  10915.   if (original_result_rtx)
  10916.     fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
  10917.  
  10918.   /* Finish building code that will trigger warnings if users forget
  10919.      to make their functions return values.  */
  10920.   if (no_return_label || cleanup_label)
  10921.     emit_jump (return_label);
  10922.   if (no_return_label)
  10923.     {
  10924.       /* We don't need to call `expand_*_return' here because we
  10925.      don't need any cleanups here--this path of code is only
  10926.      for error checking purposes.  */
  10927.       expand_label (no_return_label);
  10928.     }
  10929.  
  10930.   /* reset scope for C++: if we were in the scope of a class,
  10931.      then when we finish this function, we are not longer so.
  10932.      This cannot be done until we know for sure that no more
  10933.      class members will ever be referenced in this function
  10934.      (i.e., calls to destructors).  */
  10935.   if (current_class_name)
  10936.     {
  10937.       ctype = current_class_type;
  10938.       popclass (1);
  10939.     }
  10940.   else
  10941.     pop_memoized_context (1);
  10942.  
  10943.   /* Forget about all overloaded functions defined in
  10944.      this scope which go away.  */
  10945.   while (overloads_to_forget)
  10946.     {
  10947.       IDENTIFIER_GLOBAL_VALUE (TREE_PURPOSE (overloads_to_forget))
  10948.     = TREE_VALUE (overloads_to_forget);
  10949.       overloads_to_forget = TREE_CHAIN (overloads_to_forget);
  10950.     }
  10951.  
  10952.   /* Generate rtl for function exit.  */
  10953.   expand_function_end (input_filename, lineno);
  10954.  
  10955.   /* This must come after expand_function_end because cleanups might
  10956.      have declarations (from inline functions) that need to go into
  10957.      this function's blocks.  */
  10958.   if (current_binding_level->parm_flag != 1)
  10959.     my_friendly_abort (122);
  10960.   poplevel (1, 0, 1);
  10961.  
  10962.   /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
  10963.      to the FUNCTION_DECL node itself.  */
  10964.   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
  10965.  
  10966.   /* So we can tell if jump_optimize sets it to 1.  */
  10967.   can_reach_end = 0;
  10968.  
  10969.   /* ??? Compensate for Sun brain damage in dealing with data segments
  10970.      of PIC code.  */
  10971.   if (flag_pic
  10972.       && (DECL_CONSTRUCTOR_P (fndecl)
  10973.       || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
  10974.       && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype)))
  10975.     DECL_INLINE (fndecl) = 0;
  10976.  
  10977.   if (DECL_EXTERNAL (fndecl)
  10978.       /* This function is just along for the ride.  If we can make
  10979.      it inline, that's great.  Otherwise, just punt it.  */
  10980.       && (DECL_INLINE (fndecl) == 0
  10981.       || flag_no_inline
  10982.       || function_cannot_inline_p (fndecl)))
  10983.     {
  10984.       extern int rtl_dump_and_exit;
  10985.       int old_rtl_dump_and_exit = rtl_dump_and_exit;
  10986.       int inline_spec = DECL_INLINE (fndecl);
  10987.  
  10988.       /* This throws away the code for FNDECL.  */
  10989.       rtl_dump_and_exit = 1;
  10990.       /* This throws away the memory of the code for FNDECL.  */
  10991.       if (flag_no_inline)
  10992.     DECL_INLINE (fndecl) = 0;
  10993.       rest_of_compilation (fndecl);
  10994.       rtl_dump_and_exit = old_rtl_dump_and_exit;
  10995.       DECL_INLINE (fndecl) = inline_spec;
  10996.     }
  10997.   else
  10998.     {
  10999.       /* Run the optimizers and output the assembler code for this function.  */
  11000.       rest_of_compilation (fndecl);
  11001.     }
  11002.  
  11003.   if (ctype && TREE_ASM_WRITTEN (fndecl))
  11004.     note_debug_info_needed (ctype);
  11005.  
  11006.   current_function_returns_null |= can_reach_end;
  11007.  
  11008.   /* Since we don't normally go through c_expand_return for constructors,
  11009.      this normally gets the wrong value.
  11010.      Also, named return values have their return codes emitted after
  11011.      NOTE_INSN_FUNCTION_END, confusing jump.c.  */
  11012.   if (DECL_CONSTRUCTOR_P (fndecl) || DECL_NAME (DECL_RESULT (fndecl)) != 0)
  11013.     current_function_returns_null = 0;
  11014.  
  11015.   if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
  11016.     warning ("`volatile' function does return");
  11017.   else if (warn_return_type && current_function_returns_null
  11018.        && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node)
  11019.     {
  11020.       /* If this function returns non-void and control can drop through,
  11021.      complain.  */
  11022.       pedwarn ("control reaches end of non-void function");
  11023.     }
  11024.   /* With just -W, complain only if function returns both with
  11025.      and without a value.  */
  11026.   else if (extra_warnings
  11027.        && current_function_returns_value && current_function_returns_null)
  11028.     warning ("this function may return with or without a value");
  11029.  
  11030.   /* Free all the tree nodes making up this function.  */
  11031.   /* Switch back to allocating nodes permanently
  11032.      until we start another function.  */
  11033.   permanent_allocation ();
  11034.  
  11035.   if (flag_cadillac)
  11036.     cadillac_finish_function (fndecl);
  11037.  
  11038.   if (DECL_SAVED_INSNS (fndecl) == 0)
  11039.     {
  11040.       /* Stop pointing to the local nodes about to be freed.  */
  11041.       /* But DECL_INITIAL must remain nonzero so we know this
  11042.      was an actual function definition.  */
  11043.       DECL_INITIAL (fndecl) = error_mark_node;
  11044.       if (! DECL_CONSTRUCTOR_P (fndecl)
  11045.       || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
  11046.     DECL_ARGUMENTS (fndecl) = 0;
  11047.     }
  11048.  
  11049. #ifdef MPW_ASM
  11050.   /* (should account for nesting?) */
  11051.   /* All the names that might need to be imported into this module have
  11052.      now been seen. */
  11053.   finish_module (IDENTIFIER_POINTER (DECL_NAME (fndecl)));
  11054. #endif /* MPW_ASM */
  11055.  
  11056.   /* Let the error reporting routines know that we're outside a function.  */
  11057.   current_function_decl = NULL_TREE;
  11058.   named_label_uses = NULL_TREE;
  11059.   clear_anon_parm_name ();
  11060. }
  11061.  
  11062. /* Create the FUNCTION_DECL for a function definition.
  11063.    LINE1 is the line number that the definition absolutely begins on.
  11064.    LINE2 is the line number that the name of the function appears on.
  11065.    DECLSPECS and DECLARATOR are the parts of the declaration;
  11066.    they describe the function's name and the type it returns,
  11067.    but twisted together in a fashion that parallels the syntax of C.
  11068.  
  11069.    This function creates a binding context for the function body
  11070.    as well as setting up the FUNCTION_DECL in current_function_decl.
  11071.  
  11072.    Returns a FUNCTION_DECL on success.
  11073.  
  11074.    If the DECLARATOR is not suitable for a function (it defines a datum
  11075.    instead), we return 0, which tells yyparse to report a parse error.
  11076.  
  11077.    May return void_type_node indicating that this method is actually
  11078.    a friend.  See grokfield for more details.
  11079.  
  11080.    Came here with a `.pushlevel' .
  11081.  
  11082.    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
  11083.    CHANGES TO CODE IN `grokfield'.  */
  11084. tree
  11085. start_method (declspecs, declarator, raises)
  11086.      tree declarator, declspecs, raises;
  11087. {
  11088.   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises);
  11089.  
  11090.   /* Something too ugly to handle.  */
  11091.   if (fndecl == 0)
  11092.     return 0;
  11093.  
  11094.   /* Pass friends other than inline friend functions back.  */
  11095.   if (TYPE_MAIN_VARIANT (fndecl) == void_type_node)
  11096.     return fndecl;
  11097.  
  11098.   if (TREE_CODE (fndecl) != FUNCTION_DECL)
  11099.     /* Not a function, tell parser to report parse error.  */
  11100.     return 0;
  11101.  
  11102.   if (DECL_IN_AGGR_P (fndecl))
  11103.     {
  11104.       if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
  11105.     error_with_decl (fndecl, "`%s' is already defined in class %s",
  11106.              TYPE_NAME_STRING (DECL_CONTEXT (fndecl)));
  11107.       return void_type_node;
  11108.     }
  11109.  
  11110.   /* If we're expanding a template, a function must be explicitly declared
  11111.      inline if we're to compile it now.  If it isn't, we have to wait to see
  11112.      whether it's needed, and whether an override exists.  */
  11113.   if (flag_default_inline && !processing_template_defn)
  11114.     DECL_INLINE (fndecl) = 1;
  11115.  
  11116.   /* We read in the parameters on the maybepermanent_obstack,
  11117.      but we won't be getting back to them until after we
  11118.      may have clobbered them.  So the call to preserve_data
  11119.      will keep them safe.  */
  11120.   preserve_data ();
  11121.  
  11122.   if (! DECL_FRIEND_P (fndecl))
  11123.     {
  11124.       if (DECL_CHAIN (fndecl) != NULL_TREE)
  11125.     {
  11126.       /* Need a fresh node here so that we don't get circularity
  11127.          when we link these together.  If FNDECL was a friend, then
  11128.          `pushdecl' does the right thing, which is nothing wrt its
  11129.          current value of DECL_CHAIN.  */
  11130.       fndecl = copy_node (fndecl);
  11131.     }
  11132.  
  11133.       if (DECL_CONSTRUCTOR_P (fndecl))
  11134.     grok_ctor_properties (current_class_type, fndecl);
  11135.       else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
  11136.     grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl));
  11137.     }
  11138.  
  11139.   finish_decl (fndecl, NULL, NULL, 0);
  11140.  
  11141.   /* Make a place for the parms */
  11142.   pushlevel (0);
  11143.   current_binding_level->parm_flag = 1;
  11144.   
  11145.   DECL_IN_AGGR_P (fndecl) = 1;
  11146.   return fndecl;
  11147. }
  11148.  
  11149. /* Go through the motions of finishing a function definition.
  11150.    We don't compile this method until after the whole class has
  11151.    been processed.
  11152.  
  11153.    FINISH_METHOD must return something that looks as though it
  11154.    came from GROKFIELD (since we are defining a method, after all).
  11155.  
  11156.    This is called after parsing the body of the function definition.
  11157.    STMTS is the chain of statements that makes up the function body.
  11158.  
  11159.    DECL is the ..._DECL that `start_method' provided.  */
  11160.  
  11161. tree
  11162. finish_method (decl)
  11163.      tree decl;
  11164. {
  11165.   register tree fndecl = decl;
  11166.   tree old_initial;
  11167.   tree context = DECL_CONTEXT (fndecl);
  11168.  
  11169.   register tree link;
  11170.  
  11171.   if (TYPE_MAIN_VARIANT (decl) == void_type_node)
  11172.     return decl;
  11173.  
  11174. #ifdef DEBUG_CP_BINDING_LEVELS
  11175.   indent_to (stderr, debug_bindings_indentation);
  11176.   fprintf (stderr, "finish_method");
  11177.   debug_bindings_indentation += 4;
  11178. #endif
  11179.  
  11180.   old_initial = DECL_INITIAL (fndecl);
  11181.  
  11182.   /* Undo the level for the parms (from start_method).
  11183.      This is like poplevel, but it causes nothing to be
  11184.      saved.  Saving information here confuses symbol-table
  11185.      output routines.  Besides, this information will
  11186.      be correctly output when this method is actually
  11187.      compiled.  */
  11188.  
  11189.   /* Clear out the meanings of the local variables of this level;
  11190.      also record in each decl which block it belongs to.  */
  11191.  
  11192.   for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
  11193.     {
  11194.       if (DECL_NAME (link) != 0)
  11195.     IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
  11196.       my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
  11197.       DECL_CONTEXT (link) = 0;
  11198.     }
  11199.  
  11200.   /* Restore all name-meanings of the outer levels
  11201.      that were shadowed by this level.  */
  11202.  
  11203.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  11204.       IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  11205.   for (link = current_binding_level->class_shadowed;
  11206.        link; link = TREE_CHAIN (link))
  11207.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  11208.   for (link = current_binding_level->type_shadowed;
  11209.        link; link = TREE_CHAIN (link))
  11210.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  11211.  
  11212.   GNU_xref_end_scope (current_binding_level,
  11213.               current_binding_level->level_chain,
  11214.               current_binding_level->parm_flag,
  11215.               current_binding_level->keep,
  11216.               current_binding_level->tag_transparent);
  11217.  
  11218.   pop_binding_level ();
  11219.  
  11220.   DECL_INITIAL (fndecl) = old_initial;
  11221. #if 0
  11222.   /* tiemann would like this, but is causes String.cc to not compile. */
  11223.   if (DECL_FRIEND_P (fndecl) || DECL_CONTEXT (fndecl) != current_class_type)
  11224. #else
  11225.   if (DECL_FRIEND_P (fndecl))
  11226. #endif
  11227.     {
  11228.       CLASSTYPE_INLINE_FRIENDS (current_class_type)
  11229.     = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
  11230.       decl = void_type_node;
  11231.     }
  11232. #if 0
  11233.   /* Work in progress, 9/17/92. */
  11234.   else if (context != current_class_type
  11235.        && TREE_CHAIN (context) != NULL_TREE
  11236.        && !DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
  11237.     {
  11238.       /* Don't allow them to declare a function like this:
  11239.        class A {
  11240.        public:
  11241.          class B {
  11242.          public:
  11243.            int f();
  11244.          };
  11245.          int B::f() {}
  11246.        };
  11247.  
  11248.        Note we can get in here if it's a friend (in which case we'll
  11249.        avoid lots of nasty cruft), or it's a destructor.  Compensate.
  11250.       */
  11251.       tree tmp = DECL_ARGUMENTS (TREE_CHAIN (context));
  11252.       if (tmp
  11253.       && TREE_CODE (tmp) == IDENTIFIER_NODE
  11254.       && TREE_CHAIN (IDENTIFIER_GLOBAL_VALUE (tmp))
  11255.       && TREE_CODE (TREE_CHAIN (IDENTIFIER_GLOBAL_VALUE (tmp))) == TYPE_DECL)
  11256.     {
  11257.       error_with_decl (decl,
  11258.                "qualified name used in declaration of `%s'");
  11259.       /* Make this node virtually unusable in the end.  */
  11260.       TREE_CHAIN (decl) = NULL_TREE;
  11261.     }
  11262.     }
  11263. #endif
  11264.  
  11265. #ifdef DEBUG_CP_BINDING_LEVELS
  11266.   debug_bindings_indentation -= 4;
  11267. #endif
  11268.  
  11269.   return decl;
  11270. }
  11271.  
  11272. /* Called when a new struct TYPE is defined.
  11273.    If this structure or union completes the type of any previous
  11274.    variable declaration, lay it out and output its rtl.  */
  11275.  
  11276. void
  11277. hack_incomplete_structures (type)
  11278.      tree type;
  11279. {
  11280.   tree decl;
  11281.  
  11282.   if (current_binding_level->n_incomplete == 0)
  11283.     return;
  11284.  
  11285.   if (!type) /* Don't do this for class templates.  */
  11286.     return;
  11287.  
  11288.   for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
  11289.     if (TREE_TYPE (decl) == type
  11290.     || (TREE_TYPE (decl)
  11291.         && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  11292.         && TREE_TYPE (TREE_TYPE (decl)) == type))
  11293.       {
  11294.     if (TREE_CODE (decl) == TYPE_DECL)
  11295.       layout_type (TREE_TYPE (decl));
  11296.     else
  11297.       {
  11298.         int toplevel = global_binding_level == current_binding_level;
  11299.         if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  11300.         && TREE_TYPE (TREE_TYPE (decl)) == type)
  11301.           layout_type (TREE_TYPE (decl));
  11302.         layout_decl (decl, 0);
  11303.         rest_of_decl_compilation (decl, 0, toplevel, 0);
  11304.         if (! toplevel)
  11305.           {
  11306.         expand_decl (decl);
  11307.         expand_decl_cleanup (decl, maybe_build_cleanup (decl));
  11308.         expand_decl_init (decl);
  11309.           }
  11310.       }
  11311.     my_friendly_assert (current_binding_level->n_incomplete > 0, 164);
  11312.     --current_binding_level->n_incomplete;
  11313.       }
  11314. }
  11315.  
  11316. /* Nonzero if presently building a cleanup.  Needed because
  11317.    SAVE_EXPRs are not the right things to use inside of cleanups.
  11318.    They are only ever evaluated once, where the cleanup
  11319.    might be evaluated several times.  In this case, a later evaluation
  11320.    of the cleanup might fill in the SAVE_EXPR_RTL, and it will
  11321.    not be valid for an earlier cleanup.  */
  11322.  
  11323. int building_cleanup;
  11324.  
  11325. /* If DECL is of a type which needs a cleanup, build that cleanup here.
  11326.    We don't build cleanups if just going for syntax checking, since
  11327.    fixup_cleanups does not know how to not handle them.
  11328.  
  11329.    Don't build these on the momentary obstack; they must live
  11330.    the life of the binding contour.  */
  11331. tree
  11332. maybe_build_cleanup (decl)
  11333.      tree decl;
  11334. {
  11335.   tree type = TREE_TYPE (decl);
  11336.   if (TYPE_NEEDS_DESTRUCTOR (type))
  11337.     {
  11338.       int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
  11339.       tree rval;
  11340.       int old_building_cleanup = building_cleanup;
  11341.       building_cleanup = 1;
  11342.  
  11343.       if (TREE_CODE (decl) != PARM_DECL)
  11344.     temp = suspend_momentary ();
  11345.  
  11346.       if (TREE_CODE (type) == ARRAY_TYPE)
  11347.     rval = decl;
  11348.       else
  11349.     {
  11350.       mark_addressable (decl);
  11351.       rval = build_unary_op (ADDR_EXPR, decl, 0);
  11352.     }
  11353.  
  11354.       /* Optimize for space over speed here.  */
  11355.       if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
  11356.       || flag_expensive_optimizations)
  11357.     flags |= LOOKUP_NONVIRTUAL;
  11358.  
  11359.       /* Use TYPE_MAIN_VARIANT so we don't get a warning about
  11360.      calling delete on a `const' variable.  */
  11361.       if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (rval))))
  11362.     rval = build1 (NOP_EXPR, TYPE_POINTER_TO (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (rval)))), rval);
  11363.  
  11364.       rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0, 0);
  11365.  
  11366.       if (TYPE_USES_VIRTUAL_BASECLASSES (type)
  11367.       && ! TYPE_HAS_DESTRUCTOR (type))
  11368.     rval = build_compound_expr (tree_cons (NULL_TREE, rval,
  11369.                            build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
  11370.  
  11371.       current_binding_level->have_cleanups = 1;
  11372.       current_binding_level->more_exceptions_ok = 0;
  11373.  
  11374.       if (TREE_CODE (decl) != PARM_DECL)
  11375.     resume_momentary (temp);
  11376.  
  11377.       building_cleanup = old_building_cleanup;
  11378.  
  11379.       return rval;
  11380.     }
  11381.   return 0;
  11382. }
  11383.  
  11384. /* Expand a C++ expression at the statement level.
  11385.    This is needed to ferret out nodes which have UNKNOWN_TYPE.
  11386.    The C++ type checker should get all of these out when
  11387.    expressions are combined with other, type-providing, expressions,
  11388.    leaving only orphan expressions, such as:
  11389.  
  11390.    &class::bar;        / / takes its address, but does nothing with it.
  11391.  
  11392.    */
  11393. void
  11394. cplus_expand_expr_stmt (exp)
  11395.      tree exp;
  11396. {
  11397.   if (TREE_TYPE (exp) == unknown_type_node)
  11398.     {
  11399.       if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
  11400.     error ("address of overloaded function with no contextual type information");
  11401.       else if (TREE_CODE (exp) == COMPONENT_REF)
  11402.     warning ("useless reference to a member function name, did you forget the ()?");
  11403.     }
  11404.   else
  11405.     {
  11406.       int remove_implicit_immediately = 0;
  11407.  
  11408.       if (TREE_CODE (exp) == FUNCTION_DECL)
  11409.     {
  11410.       warning_with_decl (exp, "reference, not call, to function `%s'");
  11411.       warning ("at this point in file");
  11412.     }
  11413.       if (TREE_RAISES (exp))
  11414.     {
  11415.       my_friendly_assert (flag_handle_exceptions, 165);
  11416.       if (flag_handle_exceptions == 2)
  11417.         {
  11418.           if (! current_binding_level->more_exceptions_ok)
  11419.         {
  11420.           extern struct nesting *nesting_stack, *block_stack;
  11421.  
  11422.           remove_implicit_immediately
  11423.             = (nesting_stack != block_stack);
  11424.           cplus_expand_start_try (1);
  11425.         }
  11426.           current_binding_level->have_exceptions = 1;
  11427.         }
  11428.     }
  11429.  
  11430.       expand_expr_stmt (break_out_cleanups (exp));
  11431.  
  11432.       if (remove_implicit_immediately)
  11433.     pop_implicit_try_blocks (NULL_TREE);
  11434.     }
  11435.  
  11436.   /* Clean up any pending cleanups.  This happens when a function call
  11437.      returns a cleanup-needing value that nobody uses.  */
  11438.   expand_cleanups_to (NULL_TREE);
  11439. }
  11440.  
  11441. /* When a stmt has been parsed, this function is called.
  11442.  
  11443.    Currently, this function only does something within a
  11444.    constructor's scope: if a stmt has just assigned to this,
  11445.    and we are in a derived class, we call `emit_base_init'.  */
  11446.  
  11447. void
  11448. finish_stmt ()
  11449. {
  11450.   extern struct nesting *cond_stack, *loop_stack, *case_stack;
  11451.  
  11452.   
  11453.   if (current_function_assigns_this
  11454.       || ! current_function_just_assigned_this)
  11455.     return;
  11456.   if (DECL_CONSTRUCTOR_P (current_function_decl))
  11457.     {
  11458.       /* Constructors must wait until we are out of control
  11459.      zones before calling base constructors.  */
  11460.       if (cond_stack || loop_stack || case_stack)
  11461.     return;
  11462.       emit_insns (base_init_insns);
  11463.       check_base_init (current_class_type);
  11464.     }
  11465.   current_function_assigns_this = 1;
  11466.  
  11467.   if (flag_cadillac)
  11468.     cadillac_finish_stmt ();
  11469. }
  11470.  
  11471. void
  11472. pop_implicit_try_blocks (decl)
  11473.      tree decl;
  11474. {
  11475.   if (decl)
  11476.     {
  11477.       my_friendly_assert (current_binding_level->parm_flag == 3, 166);
  11478.       current_binding_level->names = TREE_CHAIN (decl);
  11479.     }
  11480.  
  11481.   while (current_binding_level->parm_flag == 3)
  11482.     {
  11483.       tree name = get_identifier ("(compiler error)");
  11484.       tree orig_ex_type = current_exception_type;
  11485.       tree orig_ex_decl = current_exception_decl;
  11486.       tree orig_ex_obj = current_exception_object;
  11487.       tree decl = cplus_expand_end_try (2);
  11488.  
  11489.       /* @@ It would be nice to make all these point
  11490.      to exactly the same handler.  */
  11491.       /* Start hidden EXCEPT.  */
  11492.       cplus_expand_start_except (name, decl);
  11493.       /* reraise ALL.  */
  11494.       cplus_expand_reraise (NULL_TREE);
  11495.       current_exception_type = orig_ex_type;
  11496.       current_exception_decl = orig_ex_decl;
  11497.       current_exception_object = orig_ex_obj;
  11498.       /* This will reraise for us.  */
  11499.       cplus_expand_end_except (error_mark_node);
  11500.     }
  11501.  
  11502.   if (decl)
  11503.     {
  11504.       TREE_CHAIN (decl) = current_binding_level->names;
  11505.       current_binding_level->names = decl;
  11506.     }
  11507. }
  11508.  
  11509. /* Push a cleanup onto the current binding contour that will cause
  11510.    ADDR to be cleaned up, in the case that an exception propagates
  11511.    through its binding contour.  */
  11512.  
  11513. void
  11514. push_exception_cleanup (addr)
  11515.      tree addr;
  11516. {
  11517.   tree decl = build_decl (VAR_DECL, get_identifier (EXCEPTION_CLEANUP_NAME), ptr_type_node);
  11518.   tree cleanup;
  11519.  
  11520.   decl = pushdecl (decl);
  11521.   DECL_REGISTER (decl) = 1;
  11522.   store_init_value (decl, addr);
  11523.   expand_decl (decl);
  11524.   expand_decl_init (decl);
  11525.  
  11526.   cleanup = build (COND_EXPR, integer_type_node,
  11527.            build (NE_EXPR, integer_type_node,
  11528.               decl, integer_zero_node),
  11529.            build_delete (TREE_TYPE (addr), decl,
  11530.                  lookup_name (in_charge_identifier, 0),
  11531.                  LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0, 0),
  11532.            integer_zero_node);
  11533.   expand_decl_cleanup (decl, cleanup);
  11534. }
  11535.  
  11536. /* For each binding contour, emit code that deactivates the
  11537.    exception cleanups.  All other cleanups are left as they were.  */
  11538.  
  11539. static void
  11540. deactivate_exception_cleanups ()
  11541. {
  11542.   struct binding_level *b = current_binding_level;
  11543.   tree xyzzy = get_identifier (EXCEPTION_CLEANUP_NAME);
  11544.   while (b != class_binding_level)
  11545.     {
  11546.       if (b->parm_flag == 3)
  11547.     {
  11548.       tree decls = b->names;
  11549.       while (decls)
  11550.         {
  11551.           if (DECL_NAME (decls) == xyzzy)
  11552.         expand_assignment (decls, integer_zero_node, 0, 0);
  11553.           decls = TREE_CHAIN (decls);
  11554.         }
  11555.     }
  11556.       b = b->level_chain;
  11557.     }
  11558. }
  11559.  
  11560. /* Change a static member function definition into a FUNCTION_TYPE, instead
  11561.    of the METHOD_TYPE that we create when it's originally parsed.  */
  11562. static void
  11563. revert_static_member_fn (fn, decl, argtypes)
  11564.      tree *fn, *decl, *argtypes;
  11565. {
  11566.   tree tmp, function = *fn;
  11567.  
  11568.   *argtypes = TREE_CHAIN (*argtypes);
  11569.   tmp = build_function_type (TREE_TYPE (function), *argtypes);
  11570.   tmp = build_type_variant (tmp, TYPE_READONLY (function),
  11571.                 TYPE_VOLATILE (function));
  11572.   tmp = build_exception_variant (TYPE_METHOD_BASETYPE (function), tmp,
  11573.                  TYPE_RAISES_EXCEPTIONS (function));
  11574.   TREE_TYPE (*decl) = tmp;
  11575.   *fn = tmp;
  11576.   DECL_STATIC_FUNCTION_P (*decl) = 1;
  11577. }
  11578.